set icon application

Hello,

im trying to set a new icon for my application. However i tried several files, and it seems the icon does not update well on "file explorer" in windows, after building .exe

for example if i drop the .exe in a folder i have never put the exe in, the icon shows up properly with the last version. but if i drop the .exe in a folder it has already been, the .exe take old version of the icon.

i guess i do not delete things right, or do not free some memory when i close my application ?

i load the icon this way, after creating the resource file:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
		wc.cbSize = sizeof(WNDCLASSEX);
		wc.style = 0;
		wc.lpfnWndProc = WindowProc;
		wc.cbClsExtra = 0;
		wc.cbWndExtra = 0;
		wc.hInstance = hInstance;
		//wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
		wc.hIcon = LoadIcon(NULL, (LPCSTR)IDI_ICON1);
		wc.hCursor = LoadCursor(NULL, IDC_ARROW);
		wc.hbrBackground = CreateSolidBrush(RGB(240, 240, 240));
		wc.lpszMenuName = NULL;
		wc.lpszClassName = szAppName;
		wc.hIconSm = LoadIcon(NULL, (LPCSTR)IDI_ICON1);
		RegisterClassEx(&wc);
		hWnd = CreateWindowEx(WS_EX_CLIENTEDGE, szAppName, "", WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX, a, b, c, d, NULL, NULL, hInstance, NULL);

what should i do ?
Last edited on
Normally the icon is part of the .res file and the .res file is part of the .exe file so it doesnt't matter where the .exe is located.
However when you replace or change the icon you need to rebuild the app completely.
yeah, it does not seem to make sense right ? aha

i got an answer in another forum, and it seems to be a "caching" problem of windows itself, which should disappear after a simple reboot - but not in my case. I manually clear the icons cache and everthing is fine now:

https://neosmart.net/wiki/clear-icons-cache/#How_to_clear_the_icons_cache_in_Windows_8_or_81

thanks anyway !
Last edited on
closed account (E0p9LyTq)
When using an application defined icon you have to specify the module's instance to load the resource, using its handle:
wc.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1));
https://msdn.microsoft.com/en-us/library/windows/desktop/ms648072(v=vs.85).aspx

LoadIcon() has been superseded by LoadImage():

wc.hIcon = (HICON) LoadImage(hInstance, MAKEINTRESOURCE(IDI_ICON1), IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR);
https://msdn.microsoft.com/en-us/library/windows/desktop/ms648045(v=vs.85).aspx

For a builtin Windows icon or cursor here's how to use LoadImage():
1
2
wc.hIcon   = (HICON)   LoadImage(NULL, IDI_APPLICATION, IMAGE_ICON, 0, 0, LR_SHARED)
wc.hCursor = (HCURSOR) LoadImage(NULL, IDC_ARROW, IMAGE_CURSOR, 0, 0, LR_SHARED);

Topic archived. No new replies allowed.