05 Windows編程——Windows程式架構

來源:互聯網
上載者:User

標籤:none   ati   use   over   表單   info   技術   patch   one   

源碼

 1 #include<Windows.h> 2  3 LRESULT CALLBACK WindProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam); 4  5 int WinMain(HINSTANCE hInst, HINSTANCE tmp, LPSTR szCmd, int nShow) 6 { 7     WNDCLASS WndClass; 8     TCHAR* ClassName = TEXT("MyClass"); 9     HWND hwnd;10     MSG msg;11 12     WndClass.cbClsExtra = 0;13     WndClass.cbWndExtra = 0;14     WndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);15     WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);16     WndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);17     WndClass.hInstance = hInst;18     WndClass.lpfnWndProc = WindProc;19     WndClass.lpszClassName = ClassName;20     WndClass.lpszMenuName = NULL;21     WndClass.style = CS_VREDRAW | CS_HREDRAW;22 23     if (!RegisterClass(&WndClass))24     {25         MessageBox(NULL, TEXT("Gegister Class Fail!!"), TEXT("error"), MB_OK);26         return 0;27     }28 29     hwnd = CreateWindow(ClassName, TEXT("Hello"), WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 500, 300, NULL, NULL, hInst, NULL);30     if (hwnd == NULL)31     {32         MessageBox(NULL, TEXT("Create Window Fail!!"), TEXT("error"), MB_OK);33         return 0;34     }35     ShowWindow(hwnd, nShow);36     UpdateWindow(hwnd);37 38     while (GetMessage(&msg,NULL,0,0))39     {40         TranslateMessage(&msg);41         DispatchMessage(&msg);42     }43 44     return 0;45 }46 47 LRESULT CALLBACK WindProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)48 {49     switch (message)50     {51     case WM_DESTROY:52         PostQuitMessage(0);//發送WM_QUIT訊息53         return 0;54     default:55         break;56     }57 58     return DefWindowProc(hwnd, message, wParam, lParam);59 }
View Code

 

 WIndows表單程式的一生 ,大部分時間都在訊息迴圈中度過。

 

05 Windows編程——Windows程式架構

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.