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
| #include<Windows.h> #include<iostream> #include<CommCtrl.h> LRESULT CALLBACK WindowProc( _In_ HWND hwnd, _In_ UINT uMsg, _In_ WPARAM wParam, _In_ LPARAM lParam ) { static HINSTANCE hInstance = GetModuleHandleW(NULL); switch (uMsg) { case WM_CREATE: CreateWindowW(WC_BUTTON, L"按钮1", WS_CHILD | WS_VISIBLE, 10, 10, 100, 40, hwnd, (HMENU)0x100, hInstance, 0); break; case WM_CLOSE: MessageBoxW(hwnd, L"窗口关闭了", L"提示", MB_OK); DestroyWindow(hwnd); PostQuitMessage(0); break; default: break; } return DefWindowProcW(hwnd, uMsg, wParam, lParam); } int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPreInstance, LPSTR lpCmdeLine, int nCmdShow ) { WNDCLASSW myClass = { 0 }; myClass.lpszClassName = L"51hook"; myClass.lpfnWndProc = WindowProc; RegisterClassW(&myClass); HWND hwindow = CreateWindowW( myClass.lpszClassName, L"51hook", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, 0 ); ShowWindow(hwindow, SW_SHOWNORMAL);
MSG msg = { 0 }; while (GetMessageW(&msg, 0, 0, 0)) { DispatchMessageW(&msg); }
return 0; }
|