Hey everyone.
I can not figure this out. I have a picturebox control (ID 8001) on my main dialog. I want to replace and updating this control's Bitmap with a function, allowing me to select different Bitmap (logos) to effectively replace/update the picturebox control.
But nothing takes effect. And I just cant figure it out.
I'll break down what I did to try to accomplish this.
I added 3 Bitmaps using the resource editor Import > select BMP etc
In resource tree I have
main.rc > Bitmap >
#8002
#8003
#8004
And this reflects in the main.rc file
CONTROL "", 8001, "Static", SS_ICON|SS_CENTERIMAGE, 4, 192, 32, 24
8002 BITMAP "assets\\vendors\\vendor_logo_amd.bmp"
8003 BITMAP "assets\\vendors\\vendor_logo_intel.bmp"
8004 BITMAP "assets\\vendors\\vendor_logo_nvidia.bmp"
And in main.h
#define IDR_ICO_MAIN 8001
#define VENDOR_LOGO_AMD 8002
#define VENDOR_LOGO_NVIDIA 8003
#define VENDOR_LOGO_INTEL 8004
It is ID 8001 (the picturebox ID) I want to update with this function
static HWND vendorLogo;
void SetVendorLogo(HWND hDlg, int controlId, int imageId) {
HBITMAP hBitmap = LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(imageId));
if (hBitmap) {
HBITMAP hOldBitmap = (HBITMAP)SendMessage(vendorLogo, STM_GETIMAGE, (WPARAM)IMAGE_BITMAP, 0);
SendMessage(vendorLogo, STM_SETIMAGE, (WPARAM)IMAGE_BITMAP, (LPARAM)hBitmap);
InvalidateRect(vendorLogo, NULL, TRUE);
if (hOldBitmap) {
DeleteObject(hOldBitmap);
}
} else {
MessageBox(hDlg, L"Bitmap loading failed", L"Error", MB_ICONERROR);
return;
}
}
And I call like so
SetVendorLogo(hWnd, 8001, VENDOR_LOGO_INTEL);
But the image never updates and remains blank (empty) at all times. Can anyone tell me why this is happening, and how I can resolve this?
The picturebox coordinates are perfect as was used with the main application icon all along, until we wish to update/replace picturebox, in case this raises question.
Thank you