One of the simplest windows must include two functions:
1. Entry function: WinMain
2. Window procedure callback function: WndProc
The structure is as follows:
1#include <windows.h>2 3 //window procedure callback function4 LRESULT CALLBACK WndProc (HWND hwnd, UINT MSG, WPARAM WPARAM, LPARAM LPARAM)5 {6 //processing of various messages7 Switch(msg)8 {9 Casewm_create:Ten One Break; A - - default: the Break; - } - - returnDefWindowProc (hwnd, MSG, wparam, lparam);//send the message to the system to handle it. + } - + A //equivalent to the main function in the C language. Returns the parameters of the message at intWINAPI WinMain (HInstance hinstance,//Current instance handle - hinstance Hprevinsttance, - PSTR CmdLine, - intcmdshow) - { - msg msg; in //1. Create a window - wndclass wndclass; to //1.1 Design window class +Wndclass.lpfnwndproc =(WNDPROC) WNDPROC; - //set the remaining properties of Wndclass the //2.2 Register window class * if(! RegisterClass (&wndclass)) $ return 0;Panax Notoginseng //2.3 Creating Windows -HWND hwd = CreateWindow ("Z","X", the Ws_overlappedwindow, + -, A 0, the -, + $, - NULL, $ NULL, $ hinstance, - NULL); - //2.4 Displaying and updating Windows the ShowWindow (HWD, cmdshow); - UpdateWindow (HWD);Wuyi //2. Message Loops the while(GetMessage (&msg,null,0,0))//getmessage The message in the message queue and put it in Msg. - { WuTranslateMessage (&MSG);//translating keyboard Messages -DispatchMessage (&MSG);//Send to WndProc processing About } $ returnMsg.wparam;//returns the parameters of the message -}
Windows programming 1