單實例運行-2 (使用互斥Mutex)

//Project.cpp

WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
    HANDLE  hMutexHandle = CreateMutex(NULL,true,"Application Already Run!");

    if (GetLastError()!=ERROR_ALREADY_EXISTS)
    {
        Application->MessageBox("Application Already Run!","Warnning", MB_OK|MB_ICONWARNING);
        ReleaseMutex(hMutexHandle);
        CloseHandle(hMutexHandle);
        return 0;
    }

try
{
    Application->Initialize();
    ....
}
catch (Exception &exception)
....
}

//附:簡單方法---在Examples中有個控件:在/Controls/SingleInst目錄下.

你可能感兴趣的:(exception,null,application,winapi)