I’m currently making a dialog which holds a picture control. I set the type to BITMAP and set the image to the image I want it too. This image is also in the resource .rc file. When I set this as the bitmap for the picture control I can see it just fine in the editor, when I run my application however it does not work, I don’t see anything in the picture control.
I’ve tried the following:
Call Initcommoncontrols(); ( this function is deprecated so I tried the InitCommonControlsEx() with the argument it wanted ) Result: Still no picture
I used the following snippet when the form is initialized:
SendMessage( GetDlgItem( aHWND, HEADERLOGO), STM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hBitmap );
hBitmap is declared as:
HBITMAP hBitmap = LoadBitmap( hInstance, MAKEINTRESOURCE(BITMAP_LOGO) );
When I did getlasterror after LoadBitmap() the error code was: 1814 (0x716) which translates too ERROR_RESOURCE_NAME_NOT_FOUND
I have no clue why the image could not be found, I can see the thing just fine in the editor, get no complaints about it. hInstance is obtained from WinMain(), I also tried getting it using this snippet:
(HINSTANCE)GetWindowLong( aHWND, GWL_HINSTANCE);
I assume the WinMain HINSTANCE would be correct but just to be sure I tried this, had no effect.
After that I thought it might just be the IDE screwing up somehow so I threw away the dialog, recreated it, added new picture control, added the image again. Still same thing, looks fine in the editor but doesn’t show when running the project.
I’m guessing I’m missing something really simple here, please enlighten me.
It turned out that getting the HINSTANCE inside a dialog won’t work. It won’t be valid to application memory. If you grab the HINSTANCE you get from WinMain it will work. My engine now grabs this one and now the HBITMAP handle is filled just fine.