#include <windows.h> #include "generic.h" #include <stdio.h> const char * _className="liangshui"; ATOM atom=GlobalAddAtom("ctrl_q"); LONG onDestory(HWND,UINT,WPARAM,LPARAM); LONG onLbuttonDown(HWND,UINT,WPARAM,LPARAM); LONG onCreate(HWND,UINT,WPARAM,LPARAM); LONG onCommand(HWND,UINT,WPARAM,LPARAM); LONG onHotKey(HWND,UINT,WPARAM,LPARAM); MSGMAP_ENTRY msgEntry[]= { WM_DESTROY,onDestory, WM_LBUTTONDOWN,onLbuttonDown, WM_CREATE,onCreate, WM_COMMAND,onCommand, WM_HOTKEY,onHotKey, }; LONG onHotKey(HWND hwnd,UINT uint,WPARAM wparam,LPARAM lparam) { //MessageBox(hwnd,"你按了热键","你按了热键",MB_OK); if (MOD_CONTROL==LOWORD(lparam)&&VK_F10==HIWORD(lparam)) { MessageBox(NULL,"你按了热键 ctrl+f10","你按了热键",MB_OK); } return 0; } LONG onCommand(HWND hwnd,UINT uint,WPARAM wparam,LPARAM lparam) { return 0; } LONG onCreate(HWND hwnd,UINT uint,WPARAM wparam,LPARAM lparam) { if (!RegisterHotKey(hwnd,atom,MOD_CONTROL,VK_F10)) { char buff[100]; DWORD err=GetLastError(); sprintf(buff,"error code: %u",err); MessageBox(hwnd,buff,"test",MB_OK); } return 0; } LONG onDestory(HWND hand,UINT uint,WPARAM wparam,LPARAM lparam) { UnregisterHotKey(hand,atom); PostQuitMessage(0); return 0; } LONG onLbuttonDown(HWND hand,UINT uint,WPARAM wparam,LPARAM lparam) { //MessageBox(hand,"test","test",MB_OK); return 0; } int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow) { if (!InitAppcation(hInstance)) return 0; if(!InitInstance(hInstance,nCmdShow)) return 0; MSG msg; while(GetMessage(&msg,NULL,0,0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; } BOOL InitAppcation(HINSTANCE handel) { WNDCLASS wndclass; wndclass.cbClsExtra=0; wndclass.cbWndExtra=0; wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH); wndclass.hCursor=LoadCursor(NULL,IDC_CROSS); wndclass.hIcon=LoadIcon(NULL,IDC_APPSTARTING); wndclass.hInstance=handel; wndclass.lpfnWndProc=WinProc; wndclass.lpszMenuName=NULL; wndclass.style=CS_HREDRAW|CS_VREDRAW; wndclass.lpszClassName=_className; return RegisterClass(&wndclass); } BOOL InitInstance(HINSTANCE h,int i) { HWND handle =CreateWindow(_className,_className,WS_OVERLAPPEDWINDOW, CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,h,NULL); if(!handle) return FALSE; ShowWindow(handle,i); UpdateWindow(handle); return TRUE; } LRESULT CALLBACK WinProc(HWND hand,UINT uint,WPARAM wparam,LPARAM lparam) { for(int i=0;i<mid(msgEntry);++i) { if (uint==msgEntry[i].nMessage) { msgEntry[i].pMsgPro(hand,uint,wparam,lparam); } } return DefWindowProc(hand,uint,wparam,lparam); } #define mid(x) (sizeof(x)/sizeof(x[0])) BOOL InitAppcation(HINSTANCE); BOOL InitInstance(HINSTANCE,int); LRESULT CALLBACK WinProc(HWND,UINT,WPARAM,LPARAM); LRESULT CALLBACK About(HWND,UINT,WPARAM,LPARAM); typedef struct AFX_MSGMAP_ENTRY { UINT nMessage; LONG (*pMsgPro)(HWND hand,UINT uint,WPARAM wparam,LPARAM lparam); }MSGMAP_ENTRY;