Resizing icon on a button
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: Resizing icon on a button

  1. #1
    Join Date
    Sep 2005
    Posts
    131

    Resizing icon on a button

    How can I resize an icon before applying it to a button. Please see the image below:

    For applying the icon on the button , i set the ICON flag of the Button to true and used the following code:

    Code:
    	HICON DSN_ICON = AfxGetApp()->LoadIcon(IDI_MOVE_UP);
    	CButton* btn = (CButton*)GetDlgItem(IDC_MOVE_UP);
    	btn->SetIcon(DSN_ICON);
    Attached Images Attached Images  

  2. #2
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: Resizing icon on a button

    I'm not sure what you want. Resize it how? Bigger, smaller? You can put several icons inside the same .ico file, each one with a unique size and color depth.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  3. #3
    Join Date
    Sep 2005
    Posts
    131

    Re: Resizing icon on a button

    I want the icon to appear smaller. Just like the icon shown on right image in my previous post.

  4. #4
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: Resizing icon on a button

    Put both a 32x32 and 16x16 pixels in your .ico file and it will show like that.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  5. #5
    Join Date
    Sep 2005
    Posts
    131

    Re: Resizing icon on a button

    Well, my icon is already of 16x16 size. But it is still showing bigger picture.

    Actually, I tried it with both 32*32 and 16*16 size, but in both cases the result is same except the picture quality.....

    btw, how can we put 2 icons in the same file?

  6. #6
    Join Date
    Jul 2005
    Location
    Germany
    Posts
    1,194

    Re: Resizing icon on a button

    Try LoadImage() instead of LoadIcon(). With this function you can specify the size (16x16).
    Please don't forget to rate users who helped you!

  7. #7
    Join Date
    Sep 2005
    Posts
    131

    Re: Resizing icon on a button

    Thanks a lot. It worked. Posting the solution as it might help others also.

    HICON DSN_ICON = (HICON)::LoadImage(GetModuleHandle("Wizards.dll"), MAKEINTRESOURCE(IDI_MOVE_UP), IMAGE_ICON, 16, 16, 0);
    CButton* btn = (CButton*)GetDlgItem(IDC_MOVE_UP);

    btn->SetIcon(DSN_ICON);


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This a Codeguru.com survey!


On-Demand Webinars (sponsored)