用MFC能否实现这功能关闭自己程序,然后重新启动自己

解决方案 »

  1.   

    可否借助另外一个进程?进程A启动进程B
    进程B干掉进程A
    进程B启动进程A
    进程A干掉进程B没做过,不知是否可行
      

  2.   

    HINSTANCE ShellExecute(
        HWND hwnd, 
        LPCTSTR lpVerb,
        LPCTSTR lpFile, 
        LPCTSTR lpParameters, 
        LPCTSTR lpDirectory,
        INT nShowCmd
    );
      

  3.   

    void ReStart(BOOL bNormal)
    {
    PROCESS_INFORMATION info;
    STARTUPINFO startup;
    char szPath[128];
    char *szCmdLine; GetModuleFileName(AfxGetApp()->m_hInstance, szPath, sizeof(szPath));
    szCmdLine = GetCommandLine();
    GetStartupInfo(&startup); BOOL bSucc = CreateProcess(szPath, szCmdLine, NULL, NULL,
    FALSE, NORMAL_PRIORITY_CLASS, NULL, NULL, &startup, &info); if(bNormal && bSucc)
    {
    CWnd *pWnd = AfxGetMainWnd(); if(pWnd != NULL)
    {
    pWnd->PostMessage(WM_CLOSE, 0, 0);
    }
    else
    ExitProcess(-1);
    }
    else
    ExitProcess(-1);
    }