I have spent half the day trying to get a bitmap to load. As far as I can tell, I'm doing everything right, but it's not working.
I am trying to build a static MFC library using Visual Studio 2022. Other projects in this solution use bitmaps with no problem. Before I began work, this project had no bitmaps.
I used the resource editor to import a bitmap. The .rc file contains this:
IDB_BITMAP1 BITMAP "C:\\ProgrammingProjects\\logix-designer\\RSLogix5000\\GUI\\DSI\\nodeExpanded.bmp"
The .rc file #includes a file named "PVGridResources.h". That file includes this:
#define IDB_BITMAP1 16000
My class has two private CBitmap members. Attempts to call LoadBitmap() on them from the constructor return 0, which means that the resource failed to load, but there is no indication of a reason. So, I created a method named LoadTheBitmap() and call it after the object is constructed. For now, I'm just trying to load a bitmap into a locally declared CBitmap object, and I'm using the lowest-level bitmap methods there are:
void CPVTreeCtrlButton::LoadTheBitmap()
{
HINSTANCE hResources = AfxGetResourceHandle();
HBITMAP bitmapHandle = ::LoadBitmap(hResources,
MAKEINTRESOURCE(IDB_BITMAP1));
}
hResources is non-null, which means the call to AfxGetResourceHandle() worked. But bitmapHandle comes back as 0, which means that once again the bitmap wasn't loaded.
The path of the bitmap file was automatically inserted into the resource file by Visual Studio, and I did not change it. Therefore, I know that the file exists.
What else can I try? What else would you like me to show you?