I've been trying to get LoadBitmap()
to work for some time now. It's returning error 1814, ERROR_RESOURCE_NAME_NOT_FOUND
. Code below, but so far I've tried:
- Using
(HBITMAP)LoadImage()
instead ofLoadBitmap()
- Using
MAKEINTRESOURCE('ICON.BMP')
instead of the resource idenfitier - Changing the filename, resource idenfitier name and resource type of the bitmap, as well as trying it with full path name or file name only
- Using
GetModuleHandle(NULL)
instead of passing the instance handle to the function - Separating
MAKEINTRESOURCE
and putting it behind its own error check just to make sure the problem isn't there (it's not) - Checking compiler and linker for updates
- Stepping through the debugger
I've also been through every SO question I could find about this, other sites, MSDN documentation, and tried applying what I found there, to no avail. What am I missing?
Using MinGW on Eclipse
resource.rc
#include "resource.h"
IDBMP_TREEICON BITMAP "icon.bmp"
resource.h
#ifndef __RESOURCE_H_INCLUDED__
#define __RESOURCE_H_INCLUDED__
#define IDBMP_TREEICON 101
#endif
main.cpp
#include <windows.h>
#include <stdio.h>
#include <commctrl.h>
#include <string>
#include "resource.h"
BOOL InitTreeViewImage(HINSTANCE hInstance, HWND hWnd){
HBITMAP hbmp = NULL;
HIMAGELIST hImgList;
if((hImgList = ImageList_Create(10, 10, FALSE, 1, 0)) == NULL){
MessageBox(NULL, "Failed to create ImageList!", "Eror", MB_OK);
return false;
}
LPCSTR theBitmap = NULL;
theBitmap = MAKEINTRESOURCE(IDBMP_TREEICON);
if(theBitmap == NULL){
//GetLastError(), output to console, messagebox - removed for brevity in this example
return false;
}
hbmp = LoadBitmap(hInstance, theBitmap);
if(hbmp == NULL){
//GetLastError(), output to console, messagebox - removed for brevity in this example
return false;
}
treeIcon = ImageList_Add(hImgList, hbmp, NULL);
if(treeIcon == 1){
MessageBox(NULL, "Failed to add icon to image list!", "Eror", MB_OK);
return false;
}
DeleteObject(hbmp);
TreeView_SetImageList(hWnd, hImgList, TVSIL_NORMAL);
return true;
}