#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;
}
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;
}
//老兄,判断是否按下IDOK,而不是IDYES.你在MessageBox中放下的是MB_OK,ok键。程序当然不会停止