Just to make sure that I have correctly understood your question…Everything compiles fine when you set the type of your resource file to "Resource Compiler", right? That is the correct setting, leave it there. The other stuff is for .NET applications.
So the problem is just that you aren't seeing the icon? What size icon did you create in the editor? The LoadIcon
function is extremely old and can only load icons with the default size, generally 32x32. If you want to load icons with a different size, you will need to use the LoadImage
function instead. Over 99% of the time, that's the function you should call to load icons. I haven't used LoadIcon
in years.
HICON hIcon = static_cast<HICON>(::LoadImage(hInstance,
MAKEINTRESOURCE(MYICON1),
IMAGE_ICON,
48, 48, // or whatever size icon you want to load
LR_DEFAULTCOLOR);
Like Retired Ninja suggests in his comment, be sure to test the return values of functions when the code doesn't work as expected. For example, test whether hIcon
is NULL
. If so, the LoadImage
function failed, and you need to figure out why. Most likely, the parameters you passed were incorrect. Either there is no resource with that ID in your application module, or there is no icon with the corresponding size in the icon file.
Another tip for debugging purposes is to use one of the built-in system icons. If you can see that icon, you know everything is working correctly, and you can start swapping things out to load your custom icon. For example:
HICON hIcon = static_cast<HICON>(::LoadImage(NULL,
MAKEINTRESOURCE(IDI_WARNING),
IMAGE_ICON,
0, 0,
LR_DEFAULTCOLOR | LR_SHARED | LR_DEFAULTSIZE));
That should show the standard warning icon, like the one you see in a message box. If that works, but loading your own icon doesn't work, the problem is very likely to be with the .ico file that you created.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…