1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
| #include<Windows.h> #include<iostream> int a = 1;
const UINT WM_USERMSG = WM_USER + 1; void print(LPCWSTR format, ...) { WCHAR wchar_buff[100]{ 0 }; va_list arglist; va_start(arglist, format); wvsprintfW(wchar_buff, format, arglist); va_end(arglist); OutputDebugStringW(wchar_buff);
}
LRESULT CALLBACK WindowProc( _In_ HWND hwnd, _In_ UINT uMsg, _In_ WPARAM wParam, _In_ LPARAM lParam ) { switch (uMsg) { case WM_CREATE: MessageBoxW(hwnd, L"窗口创建了", L"提示", MB_OK); break; case WM_CLOSE: MessageBoxW(hwnd, L"窗口关闭了", L"提示", MB_OK); DestroyWindow(hwnd); PostQuitMessage(0); break; case WM_MOUSEMOVE: { WORD X = LOWORD(lParam); WORD Y = HIWORD(lParam); print(L"鼠标移动了!X坐标%d,Y坐标%d", X, Y); break; } case WM_LBUTTONDOWN: print(L"鼠标左键按下了/n"); SendMessageW(hwnd, WM_USERMSG, 0, 0); case WM_USERMSG: print(L"自定义消息!/n"); break; default: break; } return DefWindowProcW(hwnd, uMsg, wParam, lParam); }
int WINAPI WinMain( _In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPSTR lpCmdLine, _In_ int nCmdShow ) { WNDCLASSW myClass = { 0 }; myClass.lpszClassName = L"51hook"; myClass.lpfnWndProc = WindowProc; RegisterClassW(&myClass); HWND hwnd = CreateWindowW( myClass.lpszClassName, L"51hook", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, 0 );
ShowWindow(hwnd, SW_SHOWNORMAL);
MSG msg = { 0 }; while (GetMessageW(&msg,0,0,0)){ DispatchMessage(&msg); } return 0; }
|