# Include <windows. h> # include <iostream. h> // declare the window function prototype lresult callback wndproc (hwnd, uint, wparam, lparam); bool initinstance (hinstance, int ncmdshow); void mypaint (HDC ); atom myregisterclass (hinstance); hinstance hinst; Hpen [7]; hbrush hbru [7]; int SPEN [7] = {ps_solid, ps_dash, ps_dot, ps_dashdot, cursor, ps_null, ps_insideframe}; int sbru [7] = {hs_vertical, hs_horizontal, hs_cross, hs_dia Gcross, hs_fdiagonal, hs_bdiagonal}; // functions // The main function int winapi winmain (hinstance, hinstance preinstance, lpstr lpcmdline, int ncmdshow) {// defines the window handle MSG; // define a variable myregisterclass (hinstance) used to store messages; If (! Initinstance (hinstance, ncmdshow) return false; while (getmessage (& MSG, null, 0, 0) // message loop {translatemessage (& MSG); dispatchmessage (& MSG );} return MSG. wparam;} // ------------------------------------- // The Message Processing Window Function atom myregisterclass (hinstance) {wndclassex wcex; wcex. cbsize = sizeof (wndclassex); wcex. style = cs_hredraw | cs_vredraw; wcex. lpfnwndproc = (wndproc) wndproc; wcex. cbclsextra = 0; wcex. cbwndextra = 0; wcex. hinstance = hinstance; wcex. hicon = NULL; wcex. hcursor = loadcursor (null, idc_arrow); wcex. hbrbackground = (hbrush) (color_window + 1); wcex. lpszmenuname = NULL; wcex. lpszclassname = "canvas"; wcex. hiconsm = NULL; return registerclassex (& wcex);} bool initinstance (hinstance, int ncmdshow) {hwnd; HDC; int I; hinst = hinstance; hwnd = createwindow ("canvas", "Drawing window", ws_overlappedwindow, cw_u Sedefault, 0, cw_usedefault, 0, null, null, hinstance, null); If (! Hwnd) return false; movewindow (hwnd, 10, 650,350, true); showwindow (hwnd, ncmdshow); updatewindow (hwnd); for (I = 0; I <7; I ++) {Hpen [I] = createpen (SPEN [I], 1, RGB (, 0); if (I = 6) hbru [I] = createsolidbrush (RGB (0,255, 0); elsehbru [I] = createhatchbrush (sbru [I], RGB (0,255, 0 ));} HDC = getdc (hwnd); mypaint (HDC); releasedc (hwnd, HDC); Return true;} void mypaint (HDC) {int I, x1, x2, Y; for (I = 0; I <7; I ++) {Y = (I + 1) * 30; SelectObject (HDC, Hpen [I]); movetoex (HDC, 30, Y, null); lineto (HDC, 100, Y);} X1 = 120; x2 = 180; for (I = 0; I <7; I ++) {SelectObject (HDC, hbru [I]); rectangle (HDC, X1, 30, X2, Y); X1 + = 70; x2 + = 70 ;}} lresult callback wndproc (hwnd, uint message, wparam, lparam) {paintstruct pS; HDC; int I; Switch (Message) {Case wm_paint: {HDC = beginpaint (hwnd, & PS); mypaint (HDC); endpaint (hwnd, & PS) ;} break; Case wm_destroy: {for (I = 0; I <7; I ++) {deleteobject (Hpen [I]); deleteobject (hbru [I]);} postquitmessage (0);} break; default: return defwindowproc (hwnd, message, wparam, lparam) ;}return 0 ;}