標籤:isp cal call upd 一個 tran style c語言 返回
一個最簡單的windows必須包括兩個函數:
1.入口函數:WinMain
2.視窗過程回呼函數:WndProc
結構如下:
1 #include <windows.h> 2 3 //視窗過程回呼函數 4 LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) 5 { 6 //對各種訊息進行處理 7 switch (msg) 8 { 9 case WM_CREATE:10 11 break;12 13 14 default:15 break;16 }17 18 return DefWindowProc(hwnd, msg, wparam, lparam);//把訊息轉給系統自己處理19 }20 21 22 //相當於C語言裡面的main函數。返回訊息的參數23 int WINAPI WinMain(HINSTANCE hinstance, //當前執行個體控制代碼24 HINSTANCE hPrevinsttance,25 PSTR cmdLine, 26 int cmdShow)27 {28 MSG msg;29 //1.建立視窗30 WNDCLASS wndclass;31 //1.1設計視窗類別32 wndclass.lpfnWndProc = (WNDPROC)WndProc;33 //設定wndclass的其餘屬性34 //2.2註冊視窗類別35 if (!RegisterClass(&wndclass))36 return 0;37 //2.3建立視窗38 HWND hwd = CreateWindow("Z","X",39 WS_OVERLAPPEDWINDOW,40 100,41 0,42 100,43 200,44 NULL,45 NULL,46 hinstance,47 NULL);48 //2.4顯示和更新視窗49 ShowWindow(hwd, cmdShow);50 UpdateWindow(hwd);51 //2.訊息迴圈52 while (GetMessage(&msg,NULL,0,0))//GetMessage在訊息佇列裡面去訊息放在msg裡面53 {54 TranslateMessage(&msg);//翻譯鍵盤訊息55 DispatchMessage(&msg);//發送給WndProc處理56 }57 return msg.wParam;//返回訊息的參數58 }
Windows編程1