CSDN博客

img mrdone

重启后程序自动运行

发表于2008/9/28 10:53:00  678人阅读

分类: VC/MFC

 

重启后自动运行程序的代码.
实例代码:
1、重启按钮事件中添加代码:

    g_bIsRunAgain=true;//控制是否重新运行的变量
    this->SendMessage(WM_CLOSE);
2、在OnClose()消息处理中加入代码:

     if(g_bIsRunAgain)
     {
        char pBuf[MAX_PATH];                                  //存放路径的变量
        GetCurrentDirectory(MAX_PATH,pBuf);                   //获取程序的当前目录
        strcat(pBuf,"/");
        strcat(pBuf,AfxGetApp()->m_pszExeName);   
        strcat(pBuf,".exe");         
        CString strPath= (CString) pBuf;        
        STARTUPINFO StartInfo;
        PROCESS_INFORMATION procStruct;
        memset(&StartInfo, 0, sizeof(STARTUPINFO));
        StartInfo.cb = sizeof(STARTUPINFO);
        ::CreateProcess(
            (LPCTSTR) strPath,
            NULL,
            NULL,
            NULL,
            FALSE,
            NORMAL_PRIORITY_CLASS,
            NULL,
            NULL,
            &StartInfo,
            &procStruct);
     }
     CDialog::OnClose();

0 0

相关博文

我的热门文章

img
取 消
img