#include "stdafx.h"#define VK_X 0x58int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
// TODO: Place code here.
HANDLE h = CreateMutex(NULL,TRUE,"No Previous Instance!");
if (!h)
{
MessageBox(NULL,"Fail to create Mutex !","NoPrev",
MB_OK|MB_SYSTEMMODAL);
return FALSE;
} if (GetLastError()==ERROR_ALREADY_EXISTS)
{
MessageBox(NULL,
"Previous Instance is running, the current is forbidden!",
"NoPrev",MB_OK|MB_SYSTEMMODAL);
return FALSE;
} if (!RegisterHotKey(NULL,0x0001,
MOD_CONTROL|MOD_SHIFT,VK_X))
{
MessageBox(NULL,"Fail to register hotkey Ctrl+Shift+X!",
"NoPrev",MB_OK|MB_SYSTEMMODAL);
return FALSE;
} MessageBox(NULL,
"NoPrev is running!\n\nHotkey Ctrl+Shift+X will stop NoPrev.",
"NoPrev",MB_OK|MB_SYSTEMMODAL); MSG msg;
while(GetMessage(&msg,NULL,0,0))
{
switch(msg.message)
{
case WM_HOTKEY:
if (int(msg.wParam)==0x0001)
if(MessageBox(NULL,"Stop NoPrev?","NoPrev",
MB_OK|MB_SYSTEMMODAL)==IDYES)
return FALSE;
}
} //如果不关闭互斥句柄,会有问题?
//为什么关闭互斥句柄还是不行呢?任务管理其中还是显示这个进程
CloseHandle(h); 
return TRUE;
}