(Windows Visualization Program Design: page45, page46, and page47)
// The Dig file wnd2.cpp ---------------------------------------- # include "wnd2.h" // header file in the Program <br/> // global variable <br/> char sztitle [] = "simple hello program "; // Title string <br/> char szwindowclass [] = "W32"; // window class name <br/> char szmenuname [] = "null "; // menu name, this program has no menu <br/> //****************************** ********************************** <br/> // * main function winmain * <br/> // * function: initialize and register the window class and create a window to enter the message loop and terminate the application * <br /> // * Parameters: hinstance current instance * <br/> // * previous instance of hprevinstance * <br/> // * command line of the lpcmdline * <br/> // * ncmdshow select the display window or icon * <br/> // * return value: MSG. wparam * <br/> //******************************** * ******************************** <br/> int apientry winmain (hinstance, hinstance hprevinstance, lpstr lpcmdline, int ncmdshow) <br/>{< br/> MSG; // declare the message structure object <br/> initapplication (hinstance ); // registration window <br/> // initialization <br/> If (! Initinstance (hinstance, ncmdshow) <br/> return false; <br/> // message loop <br/> while (getmessage (& MSG, null, 0, 0 )) // postquitmessage (0) ends the message loop <br/>{< br/> translatemessage (& MSG); // retrieves the message <br/> dispatchmessage (& MSG ); // send messages indirectly to function pointers <br/>}< br/> //**************** **************************************** * ********* <br/> // * function initapplication * <br/> // * function: used to register the window class * <br/> // * parameter: hinstance current instance * <br/> // * return value: If Success: returns a unique integer. If it fails, 0 * <br/> //******************************* ********************************** <br/> Atom initapplication (hinstance) <br/>{< br/> wndclass WC; // declare the window structure object <br/> // initialize the WC Domain value of the object <br/> WC. style = cs_hredraw | cs_vredraw; <br/> WC. lpfnwndproc = (wndproc) wndproc; // function pointer of the callback function <br/> WC. cbclsextra = 0; <br/> WC. cbwndextra = 0; <br/> WC. hinstance = hinstance; <br/> WC. hicon = loadicon (null, IDI _ Application); <br/> WC. hcursor = loadcursor (null, idc_arrow); <br/> WC. hbrbackground = (hbrush) getstockobject (white_brush); <br/> WC. lpszmenuname = szmenuname; <br/> WC. lpszclassname = szwindowclass; <br/> return registerclass (& WC ); // register <br/>}< br/> //************************** **************************************** <br/> // * function initinstance * <br/> // * function: used to create the main window * <br/> // * parameter: hinstance current instance * <br/> // * ncmdsh Select a display window or icon * <br/> // * return value: a non-zero value is returned after creation; otherwise, 0 * <br/> // ****************************** is returned //****************************** ********************************** <br/> bool initinstance (hinstance, int ncmdshow) <br/>{< br/> hwnd; // declare the window handle <br/> // use the createwindow function to create a window and return the handle <br/> hwnd = createwindow (// fill in the function parameters <br/> szwindowclass, // window class name <br/> sztitle, // Title Bar content <br/> ws_overlappedwindow | // display mode <br/> ws_vscroll | ws_hscroll, // horizontal and vertical rollback Animation <br/> 400, // X start coordinate <br/> 200, // y start coordinate <br/> 1024, // window width <br/> 768, // window height <br/> null, // parent window handle <br/> null, // Window menu handle <br/> hinstance, // instance handle <br/> null // additional data <br/>); <br/> If (! Hwnd) <br/> return false; // determine whether the creation is successful <br/> showwindow (hwnd, ncmdshow ); // The window is displayed when the creation is successful <br/> updatewindow (hwnd); // send the wm_paint message <br/> return true; // return the creation success mark <br/>}</P> <p> // Dig file wnd21.cpp ------------------------------------------ <br/> # include "wnd2.h" // program header file <br /> //************************************ * *************************** <br/> // * Window Function wndproc <br/> // * function: process Information in the main window <br/> // * parameter: window handle of the hwnd message <br/> // * domain in the wparam MSG message structure <br/> // * domain in the lparam MSG message structure <br/> // * return value: 0 <br/> //********************************* * ******************************* <br/> lresult callback wndproc (hwnd, uint message, wparam, lparam) <br/>{< br/> paintstruct pS; <br/> HDC; <br/> char szhello [] = "hello"; // output string content <br/> switch (Message) // filter information <br/>{< br/> case wm_paint: // draw message in the main window <br/> HDC = beginpaint (hwnd, & PS ); <br/> textout (HDC, 80,150, szhello, strlen (szhello); // output string <br/> endpaint (hwnd, & PS); <br/> break; <br/> case wm_destroy: // The window has been cleared and the program is ready to run. <br/> postquitmessage (0); // send the wm_quit message and terminate the message loop. <br/> break; <br/> default: <br/> return defwindowproc (hwnd, message, wparam, lparam); <br/>}< br/> return 0; <br/>}</P> <p> // ------------------------------------------ file wnd2.h ---------------------------------------- <br/> # include <windows. h> // windows program header file <br/> // global variable <br/> extern char sztitle []; // Title string <br/> extern char szwindowclass []; // window class name </P> <p> // function prototype declaration <br/> atom initapplication (hinstance); <br/> bool initinstance (hinstance, INT ); <br/> lresult callback wndproc (hwnd, uint, wparam, lparam); <br/> int apientry winmain (hinstance, hinstance, lpstr, INT); <br/>