Jump to content

How to change Application icon.


Vida Marcell
 Share

Recommended Posts

  • 2 months later...

 Ripped from an old thread I posted in ... back when I too pondered over the horrors of changing my applications icon.

On 3/24/2021 at 9:00 AM, SlipperyBrick said:

What a painful experience. For anyone who is looking to do the same you need to follow this process:

  • In Solution Explorer find the "Resource Files" folder (if you work in "Show all files" mode like I do you may need to switch to see the folder)
  • Right click "Resource Files" folder and select Add > Resource...
  • From the window dialog select "Icon" and choose "Import" (your icon must be .ico format)

With those steps complete, head over to wherever you have created your window and add the following code:


// Get device context
HWND hwnd = m_Window->GetHandle();
HDC hdc = GetDC(hwnd);
	
// Load the icon for window titlebar and taskbar
HICON icon = LoadIconA(GetModuleHandle(NULL), (LPCSTR)IDI_ICON1);
SendMessage(hwnd, WM_SETICON, ICON_SMALL, reinterpret_cast<LPARAM>(icon));

I would recommend to clean up your projects directory by added a "res" folder and dragging in the files that were created when you added a resource to your project.

P.S. It should go without saying but whatever variable name you have provided for your window (mine is m_Window) replace that with your own.

dHP8xID.thumb.png.58d4c0c57e313ed283c252a7b5c4f6ab.png

All jokes aside it wasn't that difficult, the worst part was trawling through the Win32 API reference and hitting dozens of deprecated pages. @reepblue looking forward to the blog post  ?

  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...