源代码如下:
CString str;
str=CCablesModelDlg::GetCurrentDirectory();
CString strpath3=str+"\\defultcables.gbl";
SHFILEOPSTRUCT FileDelete3;
FileDelete3.hwnd=this->m_hWnd;
FileDelete3.wFunc=FO_DELETE;
FileDelete3.pFrom=strpath3;
FileDelete3.pTo="";
FileDelete3.fAnyOperationsAborted=TRUE;
FileDelete3.fFlags=FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_SILENT;
FileDelete3.lpszProgressTitle="";
int c=SHFileOperation(&FileDelete3);
如上代码,defultcables.cbl就在*.exe的目录下,可是还是无法删除。GetCurrentDirectory()函数是用来获得当前运行的.exe的路径,具体实现如下:
CString CCablesModelDlg::GetCurrentDirectory()//获得当前运行的.exe的路径
{
char path[MAX_PATH];
GetModuleFileName(NULL,path,MAX_PATH);
CString str=(CString)path;
int nPos=str.ReverseFind('\\');
if (nPos==-1)
{
return "";
}
else
{
if(str.Right(1)=="\\")
str=str.Left(nPos-1);
else
str=str.Left(nPos);
}
return str;
}
CString str;
str=CCablesModelDlg::GetCurrentDirectory();
CString strpath3=str+"\\defultcables.gbl";
SHFILEOPSTRUCT FileDelete3;
FileDelete3.hwnd=this->m_hWnd;
FileDelete3.wFunc=FO_DELETE;
FileDelete3.pFrom=strpath3;
FileDelete3.pTo="";
FileDelete3.fAnyOperationsAborted=TRUE;
FileDelete3.fFlags=FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_SILENT;
FileDelete3.lpszProgressTitle="";
int c=SHFileOperation(&FileDelete3);
如上代码,defultcables.cbl就在*.exe的目录下,可是还是无法删除。GetCurrentDirectory()函数是用来获得当前运行的.exe的路径,具体实现如下:
CString CCablesModelDlg::GetCurrentDirectory()//获得当前运行的.exe的路径
{
char path[MAX_PATH];
GetModuleFileName(NULL,path,MAX_PATH);
CString str=(CString)path;
int nPos=str.ReverseFind('\\');
if (nPos==-1)
{
return "";
}
else
{
if(str.Right(1)=="\\")
str=str.Left(nPos-1);
else
str=str.Left(nPos);
}
return str;
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货