防止同一个程序运行两个实例:
在app类的cpp的InitInstance函数中:
HANDLE hMutex;
BOOL CDeskTopLockApp::InitInstance()
{
CString strName = _T("DeskTopLockApplication");
hMutex = OpenMutex(MUTEX_ALL_ACCESS, false, strName);
if(hMutex == NULL)
{
hMutex = CreateMutex(NULL,NULL,strName);
}
else
{
AfxMessageBox(_T(" 桌面锁已启动 !"));
return false;
}
……………………………………
m_nCmdShow=SW_HIDE; //程序启动时隐藏窗口A
if (!ProcessShellCommand(cmdInfo))
return FALSE;
// The one and only window has been initialized, so show and update it
m_pMainWnd->ShowWindow(SW_HIDE); //程序启动时隐藏窗口B
m_pMainWnd->UpdateWindow();
// call DragAcceptFiles only if there's a suffix
// In an SDI app, this should occur after ProcessShellCommand
return TRUE;
}
VC防止同一个程序运行两个实例
最新推荐文章于 2019-08-09 17:31:39 发布