把一个最简单的 Windows 程序源代码贴上来,免得老汉要做实验的时候每回都重头写起。
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 |
#include <windows.h> #include <tchar.h> #pragma comment(linker, "/subsystem:windows") BOOL Initialize(HINSTANCE hInstance, int iCmdShow); int Run(); LONG WINAPI MainWndProc(HWND hWnd, UINT uMsg, UINT wParam, LONG lParam); TCHAR szAppString[] = TEXT("Generic"); int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPTSTR, int iCmdShow) { if(!Initialize(hInstance, iCmdShow)) return FALSE; return Run(); } BOOL Initialize(HINSTANCE hInstance, int iCmdShow) { WNDCLASS wc = { 0 }; wc.lpfnWndProc = (WNDPROC)MainWndProc; wc.hInstance = (HINSTANCE)hInstance; wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = (HBRUSH)GetStockObject(GRAY_BRUSH); wc.lpszClassName = szAppString; if(!RegisterClass(&wc)) return FALSE; HWND hWnd = CreateWindow( szAppString, szAppString, WS_OVERLAPPEDWINDOW | WS_VISIBLE, 0, 0, 400, 300, NULL, NULL, hInstance, NULL); if(hWnd == NULL) return FALSE; ShowWindow(hWnd, iCmdShow); // display the main window UpdateWindow(hWnd); // send WM_PAINT message return TRUE; // return } int Run() { MSG msg; while(GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; } LONG APIENTRY MainWndProc(HWND hWnd, UINT uMsg, UINT wParam, LONG lParam) { switch(uMsg) { case WM_DESTROY: PostQuitMessage(0); break; default: break; } return DefWindowProc(hWnd, uMsg, wParam, lParam); } |