SHELLEXECUTEINFO ShExecInfo;
CString path_2 = L"";
TCHAR _szPath[MAX_PATH + 1] = { 0 };
BOOL RetErorr = GetModuleFileName(NULL, _szPath, MAX_PATH);
int error = GetLastError();
if (!RetErorr)
{
g_XdySimpleLog.LogLess("Get Popup windows Path Error = %d!", error);
return false;
}
(_tcsrchr(_szPath, _T('\\')))[1] = 0;//删除文件名,只获得路径 字串
path_2.Format(L"%sLoadWindow.exe", _szPath);
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = NULL;
ShExecInfo.lpFile = path_2; //上面操作获取当前程序运行目录得到想要打开的程序路径
ShExecInfo.lpParameters = L"";
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = SW_SHOW;
ShExecInfo.hInstApp = NULL;
BOOL OpenRet = ShellExecuteEx(&ShExecInfo);
int error2 = GetLastError();
if (!OpenRet) {
g_XdySimpleLog.LogLess("Open Popup windows Error = %d!", error2);
return false; //打开失败
}
return true;
关闭:
if (ShExecInfo.hProcess != NULL)
{
TerminateProcess(ShExecInfo.hProcess, 0);
ShExecInfo.hProcess = NULL;
return true; //关闭成功
}
return false; //关闭失败