大家看我下面这段代码,有错没有,怎么执行起来总错,提示"另一个程序正在使用此文件,进程无法访问".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); }

}

解决方案 »

  1.   

    在WinExec之前,把打开的文件关掉
      

  2.   

    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); }

    }