方法一:
1.使用记事本新建批处理文件Start.bat,将文件与编译的.exe程序放在同一路径下即可
@echo off
set /a num=5
:Cir
for /l %%i in (1,1,1000) do echo off
set /a num=%num%-1
if not %num%==0 goto Cir
cd /d %~dp0
start "" "DalsaDeviceBasic.exe"
exit
2.在程序中添加代码:
if (true) {
CString m_strPath;
int nPos;
GetModuleFileName(NULL, m_strPath.GetBufferSetLength(MAX_PATH + 1), MAX_PATH);
m_strPath.ReleaseBuffer();
nPos = m_strPath.ReverseFind(_T('\\'));
m_strPath = m_strPath.Left(nPos);
USES_CONVERSION;
char* tmp = W2A(m_strPath + "\\Start.bat");
system(tmp);
exit(0);
}
方法二
直接在重启按钮中加入下列代码:
::PostMessage(AfxGetMainWnd()->m_hWnd, WM_SYSCOMMAND, SC_CLOSE, NULL);
获取exe程序当前路径
extern CDalsaDeviceBasicApp theApp;
TCHAR szAppName[MAX_PATH];
::GetModuleFileName(theApp.m_hInstance, szAppName, MAX_PATH);
CString strAppFullName;
strAppFullName.Format(_T("%s"), szAppName);
STARTUPINFO StartInfo;
PROCESS_INFORMATION procStruct;
memset(&StartInfo, 0, sizeof(STARTUPINFO));
StartInfo.cb = sizeof(STARTUPINFO);
::CreateProcess(
(LPCTSTR)strAppFullName,
NULL,
NULL,
NULL,
FALSE,
NORMAL_PRIORITY_CLASS,
NULL,
NULL,
&StartInfo,
&procStruct);
|