Jump to content
Tuts 4 You

Window not showing icon


Recommended Posts

I've wrote small loader for an old crackme. This crackme searches for Olly window class and when not found my loader tries to emulate it. For this I'm creating simple window. Main window is dialog box. On dialog icon is shown normally but not on created window. I've tried many things. Using two different icons for each window, using some default icon from os, different window styles but without luck. I'm attaching full source and target. If You have some other ideas please share.


Link to comment

I would use ICON_SMALL instead of ICON_BIG for the WM_SETICON. ICON_BIG is 1, ICON_SMALL is 0, currently you are passing 1 as the value which is ICON_BIG.

IDI_ICON doesnt seem to have an id that i can see. your icon in the resource file is assigned the value of 10.

You can set IDI_ICON to 10 somewhere in code or use 10 directly instead of IDI_ICON so that it references the icon in the resource file:

10 ICON "loader.ico"

Maybe a #define IDI_ICON 10 is needed somewhere in code if not in some resource file - perhaps i missed that somewhere.

If registering a window procedure, you could save the icon loaded, so that it can be used in other WM_SETICON calls, like for dialogs or other windows in your project that the main window calls at some point.


wc.hIcon = hIcoMain;
wc.hIconSm = hIcoMain;

Then using WM_INITDIALOG is fine to put the code to load up icon for dialogs:

SendMessageA(hWnd, WM_SETICON, ICON_SMALL, hIcoMain);


  • Like 1
Link to comment

Didn't try ICON_SMALL. Will test it. -> Tested it and no difference. Dialog have icon and window not.

IDI_ICON is defined in 'resource.h' file. Icon handle is saved during initialization of dialog.

Edited by ToMKoL
added more information
Link to comment
Teddy Rogers

The API docs for WM_SETICON (and WM_GETICON) define where the icons need to be used.


The system displays the large icon in the ALT+TAB dialog box, and the small icon in the window caption.

LoadIcon uses the system default metric (icon size) of SM_CXICON and SM_CYICON. You can confirm the system size using GetSystemMetrics. If you have 32x32 icon and the system default is 16x16 it is not intended to work.

Instead of having multiple icons what I generally do is have one large icon e.g. 64x64 or 128x128 and scale icons to suite the system metrics and window DPI. If your program is DPI aware you can use a DPI value with GetSystemMetricsForDpi to get the icon dimensions that are required.

Some of the newer API's starting with Vista may be of interest. LoadIconWithScaleDown allows you to use a large icon to scale down the icon to the required size. LoadIconMetric allows you to specify the metric or size of the icon and resize up or down accordingly...


Link to comment

Problem is somewhere else. I did try some default icons from system and they also didn't work on window. On dialog any icon that I tried is displayed. On window none.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...