Win32 模版程式

來源:互聯網
上載者:User
  1 #include "windows.h"  2   3 ATOM MyRegisterClass(HINSTANCE hInstance);  4 BOOL InitInstance(HINSTANCE hInstance, int nCmdShow);  5 LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);  6   7 HINSTANCE hInst;  8   9 //********************************************************* 10 // 主程式 11 //********************************************************* 12 int APIENTRY WinMain(HINSTANCE hInstance, 13                      HINSTANCE hPrevInstance, 14                      LPSTR     lpCmdLine, 15                      int       nCmdShow) 16 { 17     MSG msg; 18  19     // 註冊視窗類別 20     MyRegisterClass(hInstance); 21  22     // 初始化 23     if (!InitInstance (hInstance, nCmdShow)) 24     { 25         return FALSE; 26     } 27  28     // 訊息迴圈 29     while (GetMessage(&msg, NULL, 0, 0)) 30     { 31         TranslateMessage(&msg); 32         DispatchMessage(&msg); 33     } 34  35     return msg.wParam; 36 } 37  38 //********************************************************* 39 // 註冊視窗類別別函數 40 //********************************************************* 41 ATOM MyRegisterClass(HINSTANCE hInstance) 42 { 43     WNDCLASSEX wcex; 44  45     wcex.cbSize        = sizeof(WNDCLASSEX);  46     wcex.style         = CS_HREDRAW | CS_VREDRAW; 47     wcex.lpfnWndProc   = WndProc; 48     wcex.cbClsExtra    = 0; 49     wcex.cbWndExtra    = 0; 50     wcex.hInstance     = hInstance; 51     wcex.hIcon         = LoadIcon(NULL, IDI_APPLICATION); 52     wcex.hCursor       = LoadCursor(NULL, IDC_ARROW); 53     wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); 54     wcex.lpszMenuName  = NULL; 55     wcex.lpszClassName = TEXT("Test"); 56     wcex.hIconSm       = NULL; 57  58     return RegisterClassEx(&wcex); 59 } 60  61 //********************************************************* 62 // 初始化函數 63 //********************************************************* 64 BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) 65 { 66     HWND hWnd; 67     hInst = hInstance; 68  69     hWnd = CreateWindow(TEXT("Test"), TEXT("Win32 Template") , WS_OVERLAPPEDWINDOW, 70         CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL); 71     if (!hWnd) 72     { 73         return FALSE; 74     } 75  76     ShowWindow(hWnd, nCmdShow); 77     UpdateWindow(hWnd); 78  79     return TRUE; 80 } 81  82 //********************************************************* 83 // 視窗過程函數 84 //********************************************************* 85 LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) 86 { 87     PAINTSTRUCT ps; 88     HDC         hdc; 89  90     switch (message)  91     { 92     case WM_PAINT: 93         hdc = BeginPaint(hWnd, &ps); 94         EndPaint(hWnd, &ps); 95         break; 96     case WM_DESTROY:  97         PostQuitMessage(0); 98         break; 99     default:             100         return DefWindowProc(hWnd, message, wParam, lParam);101     }102 103     return 0;104 }

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.