1#include <windows.h>2#include"resource.h"3 4LRESULT CALLBACK Mywndproc (HWND hwnd,//Handle to Window5UINT umsg,//message identifier6WPARAM WPARAM,//First message parameter7LPARAM LPARAM//Second message parameter8 );9 Ten intWINAPI WinMain (hinstance hinstance, hinstance hprevinstance, LPSTR lpCmdLine,intnshowcmd) One { ATCHAR szappname[] = TEXT ("Icondemo"); - wndclass wnd; - HWND hwnd; the msg msg; -Wnd.style = Cs_hredraw | Cs_vredraw;//The horizontal or vertical change window is redrawn with Mywndproc's WM_PAINT message Association -Wnd.lpfnwndproc =Mywndproc; -Wnd.cbclsextra =0; +Wnd.cbwndextra =0; -Wnd.hicon =LoadIcon (hinstance, Makeintresource (Idi_icon)); +Wnd.hcursor =loadcursor (NULL, idc_arrow); AWnd.hbrbackground =(Hbrush) getstockobject (White_brush); atWnd.lpszmenuname =NULL; -Wnd.lpszclassname = Szappname;//window class identifier, used in the first parameter of CreateWindow -Wnd.hinstance =hinstance; - if(! RegisterClass (&wnd)) - { -MessageBox (NULL, TEXT ("Unable to create window"), TEXT ("ERROR"), mb_ok|mb_iconerror); in return 0; - } to +hwnd = CreateWindow (Szappname, TEXT ("Hello"), Ws_overlappedwindow, Cw_usedefault, Cw_usedefault, Cw_usedefault, cw_usedefault, NULL, NULL, HINSTANCE, NULL);//The second argument is a window caption - ShowWindow (hwnd, nshowcmd); the UpdateWindow (HWND); * while(GetMessage (&msg, NULL,0,0)) $ {Panax NotoginsengTranslateMessage (&msg); -DispatchMessage (&msg); the } + return 0; A } the + LRESULT CALLBACK Mywndproc (HWND hwnd, UINT umsg, WPARAM WPARAM, LPARAM LPARAM) - { $HDC hdc;//defining a device environment handle $Paintstruct PS;//Drawing Structures - - StaticHicon Hicon; the Static intCxicon, Cyicon, Cxclient, cyclient; - hinstance hinstance;Wuyi intx, y; the - Switch(umsg) Wu { - About Casewm_create: $ { -HINSTANCE = ((lpcreatestruct) lParam)->hinstance;//The lparam parameter of the WM_CREATE message is a pointer to a CREATESTRUCT structure that contains hinstance. -Hicon =LoadIcon (hinstance, Makeintresource (Idi_icon)); -Cxicon = GetSystemMetrics (Sm_cxicon);//get icon size, previous LoadIcon Association ACyicon =GetSystemMetrics (Sm_cyicon); + return 0; the } - Break; $ the CaseWM_PAINT: the { theHDC = BeginPaint (hwnd, &PS); the for(y =0; Y < cyclient; Y + =Cyicon) - { in for(x =0; x < cxclient; X + =Cxicon) the { theDrawIcon (hdc, x, y, hicon);//Drawing About } the the } theEndPaint (hwnd, &PS); + - } the Break;Bayi the Casewm_size: the { -Cxclient =LoWord (lParam); -Cyclient =HiWord (lParam); the } the Break; the the CaseWm_destroy: -PostQuitMessage (0); the return 0; the } the 94 returnDefWindowProc (hwnd, umsg, WParam, LParam); the}
Note: See Windows Programming version fifth, page 334