很多时候,我们不希望用户多开客户端,这样我们需要写一些互斥代码,具体如下:
在APP文件中UINT WM_WKSTLOCK = RegisterWindowMessage(_T("Input8OnlyOne"));声明
然后在BOOL CWlqnjnApp::InitInstance()
{
HANDLE Mutex = OpenMutex(MUTEX_ALL_ACCESS, false, "Input8OneInstanceAllowed");
if (Mutex == NULL)
{
Mutex = CreateMutex(NULL, true, "Input8OneInstanceAllowed");
}
else
{
SendMessage(HWND_BROADCAST, WM_WKSTLOCK, 0, 0);
return FALSE;
}
ReleaseMutex(Mutex);
return FALSE;
}
利用互斥量即可实现客户端单开功能!