1 # include "windows. H "2 3 atom myregisterclass (hinstance); 4 bool initinstance (hinstance, int ncmdshow); 5 lresult callback wndproc (hwnd, uint message, wparam, lparam ); 6 7 hinstance hinst; 8 9 //************************************ ******************** 10 // main program 11 //*********** **************************************** * ***** 12 INT apientry winmain (hinstance Hinstance, 13 hinstance hprevinstance, 14 lpstr lpcmdline, 15 int ncmdshow) 16 {17 MSG; 18 19 // register window class 20 myregisterclass (hinstance ); 21 22 // initialize 23 if (! Initinstance (hinstance, ncmdshow) 24 {25 return false; 26} 27 28 // message loop 29 While (getmessage (& MSG, null, 0, 0 )) 30 {31 translatemessage (& MSG); 32 dispatchmessage (& MSG); 33} 34 35 return MSG. wparam; 36} 37 38 //********************************** * ********************* 39 // register window category function 40 //******* **************************************** * ********* 41 atom myregisterclass (hinstance) 42 {43 wndclassex wcex; 44 45 wcex. cbsize = sizeof (wndclassex); 46 wcex. style = cs_hredraw | cs_vredraw; 47 wcex. lpfnwndproc = wndproc; 48 wcex. cbclsextra = 0; 49 wcex. cbwndextra = 0; 50 wcex. hinstance = hinstance; 51 wcex. hicon = loadicon (null, idi_application); 52 wcex. hcursor = loadcursor (null, idc_arrow); 53 wcex. hbrbackground = (hbrush) (color_window + 1); 54 wcex. lpszmenuname = NULL; 55 wcex. LPS Zclassname = text ("test"); 56 wcex. hiconsm = NULL; 57 58 return registerclassex (& wcex ); 59} 60 61 //********************************** ********************** 62 // initialize the function 63 //********* **************************************** * ******* 64 bool initinstance (hinstance, int ncmdshow) 65 {66 hwnd; 67 hinst = hinstance; 68 69 hwnd = createwindow (text ("test"), text ("Win32 template"), ws_o Verlappedwindow, 70 cw_usedefault, 0, cw_usedefault, 0, null, null, hinstance, null); 71 If (! Hwnd) 72 {73 return false; 74} 75 76 showwindow (hwnd, ncmdshow); 77 updatewindow (hwnd); 78 79 return true; 80} 81 82 //********************************** ********************** 83 // window process function 84 //******** **************************************** * ******** 85 lresult callback wndproc (hwnd, uint message, wparam, lparam) 86 {87 paintstruct pS; 88 HDC; 89 90 switch (Message) 91 {92 case wm_paint: 93 HDC = beginpaint (hwnd, & PS); 94 endpaint (hwnd, & PS); 95break; 96 case wm_destroy: 97 postquitmessage (0); 98 break; 99 default: 100 return defwindowproc (hwnd, message, wparam, lparam); 101} 102 103 return 0; 104}