首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VC/MFC >

关于WinExec的有关问题

2012-01-22 
关于WinExec的问题.大家看我下面这段代码,有错没有,怎么执行起来总错,提示 另一个程序正在使用此文件,进

关于WinExec的问题.
大家看我下面这段代码,有错没有,怎么执行起来总错,提示 "另一个程序正在使用此文件,进程无法访问 ".

void   CTtDlg::OnButton1()  
{
//   TODO:   Add   your   control   notification   handler   code   here
CFileDialog   dlg(TRUE,   "txt ", "*.txt ");
if(dlg.DoModal()   ==   IDOK)
{
CFile   file;
VERIFY(file.Open(dlg.GetPathName(),CFile::modeRead));
CString   str= "notepad.exe     "   +   file.GetFilePath();

WinExec(str,       SW_SHOW);

}

}

[解决办法]
在WinExec之前,把打开的文件关掉
[解决办法]
没有close这个handle?
[解决办法]
fclose(fp);
[解决办法]
void CTtDlg::OnButton1()
{
// TODO: Add your control notification handler code here
CFileDialog dlg(TRUE, "txt ", "*.txt ");
if(dlg.DoModal() == IDOK)
{
CFile file;
VERIFY(file.Open(dlg.GetPathName(),CFile::modeRead));
CString str= "notepad.exe " + file.GetFilePath();
file.Close();
WinExec(str, SW_SHOW);

}

}

热点排行