function prototypes for #include <windows.h>/* window functions */lresult callback mainwndproc (hwnd, uint, Wparam, lparam); Int apientry winmain (hinstance hinstance, hinstance Hprevinstance, lpstr lpcmdline, int ncmdshow) { char szclassname[] = "Mainwclass"; wndclassex wndclass; /* fills the wndclassex structure with the parameters describing the main window */ wndclass.cbsize = sizeof (WNDCLASS); the size of the /* structure */ wndclass.style = CS_HREDRAW | CS_VREDRAW; /* specifies that if the size changes, redraw */ wndclass.lpfnwndproc = mainwndproc; /* window function Pointer */ Wndclass.cbclsextra = 0; /* no additional class memory */ wndclass.cbwndextra = 0; /* no additional window memory */ wndclass.hinstance = hinstance; /* instance handle */ wndclass.hicon = loadicon (null, idi_application);/* Use predefined icons */ wndclass.hcursor = loadcursor (null, idc_arrow); /* Use predefined Cursors */ wndclass.hbrBackground = (Hbrush) getstockobject (White_brush) /* using a white background brush */ wndclass.lpszMenuName = NULL; /* do not specify a menu */ wndclass.lpszclassname = szclassname; /* the name of the window class */&NBSP;&NBSP;&NBSP;&NBSP;WNDCLASS.HICONSM = NULL; /* Small icons with no class */ /* Register this window */ registerclassex (&wndclass); /* Creating the main window */ hwnd hwnd = createwindowex ( 0, /*dwExStyle, Extended Style */ szClassName, /*lpclassname, class name */ "my first window!", /*lpWindowName, title */ WS_OVERLAPPEDWINDOW, /*dwStyle, window Style */ CW_USEDEFAULT, /*X, initial X-coordinate */ cw_usedefault, /*Y, initial Y-coordinate */ CW_USEDEFAULT, /*nwidth, Width */ cw_usedefault, /*nHeight, Height */ NULL, /*hWndParent, parent Window Handle */ null, /*hMenu, Menu Handle */ hinstance, /*hInstance, Program Instance handle */ null); /*lpParam, User Data */ if (hwnd == null) { messagebox (null, "error build the window!", " Error ", &NBSP;MB_OK); return -1; } /* display window, Refresh window client area */ showwindow (hwnd, ncmdshow); updatewindow (HWND); /* remove the message from the message queue and give it to the window function processing, Returns false directly to GetMessage, ending the message loop */ msg msg; while (GetMessage ( &msg, null, 0, 0)) { /* Convert keyboard message */ translatemessage (&MSG); /* sends the message to the appropriate window function */ dispatchmessage (& msg); } /* when GetMessage returns FALSE, the program ends */ return msg.wparam;} Lresult callback mainwndproc (Hwnd hwnd, uint message, wparam wparam, lparam lparam) { char sztext[] = "The simplest window program! "; switch (message) { case wm_paint: /* window client area need to redraw */ { HDC hdc; PAINTSTRUCT ps; /* makes the invalid client area effective, and get the device environment handle */ hdc = beginpaint ( HWND,&NBSP;&PS); /* display text */ textout (Hdc, 10, 10, sztext, strlen (Sztext)); &Nbsp; endpaint (HWND,&NBSP;&PS); return 0; } case wm_destroy: /* is destroying the window */ /* post a WM_QUIT message to the message queue, prompting the GetMessage function to return 0, ending the message loop */ postquitmessage (0); return 0; } /* Handing out messages we don't handle to the system to do the default processing */ return defwindowproc (hwnd, message, wparam, LParam);}
Create a simple window program