How to set an icon to exe in visual studio 2017 using c++ win32 api by LoadIcon

Viewed 238

I want to set the icon by wcex.hIcon = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(SOMETHING)) where wcex is the WNDCLASSX struct object for opening the main window. I am not sure about what is SOMETHING in MAKEINTRESOURCE(SOMETHING).

I have loaded a .ico file by resource view in visual studio and I have a .rc file and the resource.h but don't know what to do with them.

After adding the .ico file the icon only appears in list of file explorer for the exe but not in taskbar or the exe window.

I am completely new to the winapi

1 Answers

LoadIcon like most resource loading functions take a HINSTANCE/HMODULE parameter that identifies the .exe/.dll file where the resource resides and a string that identifies the name of a specific resource. In addition to using a string name, Windows also supports naming resources by a number < 65536. MAKEINTRESOURCE is a macro that just casts a number to a string.

The actual name you have to use is the same as the name you (or your IDE) used when you added the icon to your .rc file.

A common pattern is to store defines with the names in a resource.h file. If you are unsure what the name is, inspect your .rc file, it should contain a line like

ICON IDI_MYICON "theIcon.ico"

where IDI_MYICON is the define you can use with MAKEINTRESOURCE.

Related