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
| #include "framework.h" #include "Win32.h"
LRESULT CALLBACK WindowsProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM rParam ) { char szOutBuff[0x80]; wsprintfA(szOutBuff, "消息类型: %lx\n", uMsg); OutputDebugStringA(szOutBuff); switch (uMsg) { case WM_DESTROY: PostQuitMessage(0); return 0; case WM_CHAR: char charBuf[16] = { 0 }; wsprintfA(charBuf, "按下: %c", (char)wParam); MessageBoxA(hwnd, charBuf, "按键提示", MB_OK | MB_ICONINFORMATION); return 0; }
return DefWindowProc(hwnd, uMsg,wParam,rParam); }
int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpCmdLine, _In_ int nCmdShow) { char szOutBuff[80]; WNDCLASS wndclass = { 0 }; TCHAR szAppName[] = TEXT("MyApp"); wndclass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH); wndclass.lpszClassName = szAppName; wndclass.hInstance = hInstance; wndclass.lpfnWndProc = WindowsProc; RegisterClass(&wndclass);
HWND hwnd = CreateWindow(szAppName,TEXT("Hello"),WS_OVERLAPPEDWINDOW,10,10,600,300,NULL,NULL,hInstance,NULL); if (hwnd == NULL) { wsprintfA(szOutBuff, "Error: %d\n", GetLastError()); OutputDebugStringA(szOutBuff); return 0; }
ShowWindow(hwnd, SW_SHOW);
MSG msg; BOOL bRet; while ((bRet = GetMessage(&msg, NULL, 0, 0)) != 0) { if (bRet == -1) { wsprintfA(szOutBuff, "Error: %d\n", GetLastError()); OutputDebugStringA(szOutBuff); } else { TranslateMessage(&msg); DispatchMessageW(&msg); } }
return 0; }
|