Reputation: 480
Trying to use Win32 API to load an icon for an application.
case WM_CREATE: {
auto hIcon = LoadImageW(NULL, L"C:\\icon.ico", IMAGE_ICON, 32, 32, LR_LOADFROMFILE);
if (hIcon) {
SendMessage(handle, WM_SETICON, ICON_BIG, (LPARAM)hIcon);
} else {
auto lastError = GetLastError();
MessageBox(handle, L"Could not load icon!", L"ERROR", MB_OK | MB_ICONERROR);
}
}
What I get is the message box as above, with lastError being 0. The icon is located at the absolute path specified, and if the file is renamed such that the path is invalid last erorr code is 2 (file not found). Therefore, I assume the icon is found.
What I've tried:
LR_LOADTRANSPARENT
.Upvotes: 0
Views: 177
Reputation: 480
The image must be an .ico
file in some specific format. The one which worked correctly for me was exporting it from GIMP with 'Windows Icon' format selected. The icon was previously in the .ico format, it just wasn't right for some reason. Examples which load it from .bmp and .png did not work for me, that works only for bitmaps, which are not icons.
If the file is found, and the formats are not correct, there won't be anything in last error.
Upvotes: 1