When you get started with MFC, you cannot understand the code. Let's start with the principle of Windows programming...
# Include <windows. h> <br/> # include <stdio. h> </P> <p> lresult callback winsunproc (hwnd, uint umsg, wparam, lparam); </P> <p> int winapi winmain (hinstance, hinstance hprevinstance, lpstr lpcmdline, int nshowcmd) {<br/> wndclass; <br/> wndclass. cbclsextra = 0; <br/> wndclass. cbwndextra = 0; <br/> wndclass. hbrbackground = (hbrush) getstockobject (black_brush); <br/> wndclass. hcu Rsor = loadcursor (null, idc_sizens); <br/> wndclass. hicon = loadicon (null, idi_question); <br/> wndclass. hinstance = hinstance; <br/> wndclass. lpfnwndproc = winsunproc; <br/> wndclass. lpszclassname = "lihan"; <br/> wndclass. lpszmenuname = NULL; <br/> wndclass. style = cs_hredraw | cs_vredraw; <br/> registerclass (& wndclass); </P> <p> hwnd; <br/> hwnd = createwindow ("lihan ", "Shijiazhuang", ws_overlappedwindow, 600, 400, null, null, hinstance, null); </P> <p> showwindow (hwnd, sw_shownormal); <br/> updatewindow (hwnd ); </P> <p> MSG; <br/> while (getmessage (& MSG, null, 0, 0) {<br/> translatemessage (& MSG ); <br/> dispatchmessage (& MSG); <br/>}< br/> return 0; <br/>}</P> <p> lresult callback winsunproc (hwnd, uint umsg, wparam, lparam) {<br/> switch (umsg) <br/>{< br/> case wm_char: <br/> char szchar [20]; <br/> sprintf (szc Har, "char is % d", wparam); <br/> MessageBox (hwnd, szchar, "lihan", 0); <br/> break; <br/> case wm_lbuttondown: <br/> MessageBox (hwnd, "click", "lihan", 0); <br/> HDC; <br/> HDC = getdc (hwnd); <br/> textout (HDC, 0, 50, "lihan", strlen ("lihan ")); <br/> releasedc (hwnd, HDC); <br/> break; <br/> case wm_paint: <br/> HDC hdc1; <br/> paintstruct pS; <br/> hdc1 = beginpaint (hwnd, & PS); <br/> textout (hdc1, 0, 0, "lihan", strlen ("lih An "); <br/> endpaint (hwnd, & PS); <br/> break; <br/> case wm_close: <br/> If (idyes = MessageBox (hwnd, "is it true? "," Lihan ", mb_yesno) {<br/> destroywindow (hwnd); <br/>}< br/> break; <br/> case wm_destroy: <br/> postquitmessage (0); <br/> break; <br/> default: <br/> return defwindowproc (hwnd, umsg, wparam, lparam ); <br/>}< br/> return 0; <br/>}</P> <p>
Running status: