在VC中,怎样不让可执行文件二次重启,或在第二次启动时自动把第一次的还原激活??

解决方案 »

  1.   

    在App类InitInstance()函数的开头增加:
    HWND *pOtherWnd = ::FindWindow(NULL, "A2");//A2是主框架的标题
    if(pOtherWnd!=NULL)
    {
    AfxMessageBox("Program already running!");
                      BringWindowToTop(pOtherWnd);
    return FALSE;
    }
      

  2.   

    .h...
    HANDLE handle;.cppBOOL C???App::InitInstance()
    {
        handle = ::CreateMutex(NULL,FALSE,_T("hello world"));
        if((::GetLastError()==ERROR_ALREADY_EXISTS) ||
        (::GetLastError()==ERROR_ACCESS_DENIED))
        {
            AfxMessageBox("running");
            return FALSE;
        }
       ...
    }