mfc program Summary

Example 1. Single-process
in InitInstance CxxApp class () code is added at the beginning of

    //利用互斥实现单例进程模式
    HANDLE   hMutex = ::CreateMutex(NULL, TRUE, _T("appIdentification"));
    if (hMutex != NULL)
    {
        if (GetLastError() == ERROR_ALREADY_EXISTS)
        {
            MessageBox(NULL, _T("程序已经运行"), _T("提示"), 0);
            CloseHandle(hMutex);
            return   FALSE;
        }
    }

Guess you like

Origin www.cnblogs.com/bhoold/p/12159093.html