Windows Programming Self-study: adding Icon Resources

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.