954,496 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Can't load bitmap resource into Image List

I have a treeview in my program for which I am adding a bitmap of an open and closed folders. I have included messageboxes to show where the program fails. It fails at the loadbitmap function. I appreciate it if anybody can tell me what is wrong. Below is the code.

hTreeView = CreateWindowEx(0, WC_TREEVIEW, (LPCTSTR)NULL,
     WS_CHILD | WS_VISIBLE | WS_THICKFRAME | TVS_HASBUTTONS | TVS_HASLINES
     | TVS_LINESATROOT | TVS_DISABLEDRAGDROP | TVS_TRACKSELECT | TVS_SINGLEEXPAND
     | TVS_FULLROWSELECT, 0, wndHeight(hToolBar), rcClient.right / 5, 
     rcClient.bottom - wndHeight (hToolBar) - wndHeight (hStatusBar),
    hwnd, (HMENU)IDC_TREEVIEW, GetModuleHandle(NULL), NULL);
 
 
 
    hImageList = ImageList_Create (16, 16, ILC_COLOR16, 2,4);
 
 
 
    if (hImageList == FALSE)
   MessageBox (NULL, TEXT ("Could not create image list"), 
   TEXT ("WARNING"), MB_ICONERROR) ;
 
 
    hBitMap = LoadBitmap (((LPCREATESTRUCT) lParam)->hInstance, MAKEINTRESOURCE(IDB_TREE));
 
 
    if (hBitMap == NULL)
   MessageBox (NULL, TEXT ("Could not load bitmap into image list"), 
   TEXT ("WARNING"), MB_ICONERROR) ;
 
 
    ImageList_Add (hImageList, hBitMap, NULL);
    DeleteObject (hBitMap);
 
 
    if (ImageList_GetImageCount(hImageList) < 2)
     MessageBox (NULL, TEXT ("Could not add images to list"), 
   TEXT ("WARNING"), MB_ICONERROR) ;
 
 
    SendMessage (GetDlgItem(hwnd, IDC_TREEVIEW), TVM_SETIMAGELIST, 
     0, (LPARAM)hImageList);


So basically I get the second error messagebox that says: "Could not load bitmap into image list"

Thank you in advance.

nhandal
Newbie Poster
5 posts since Sep 2006
Reputation Points: 27
Solved Threads: 0
 

Well, it seems likely the problem is in one of the two parameters you pass to the LoadBitmap function. You should check the return value of GetLastError after LoadBitmap fails, and look it up here .

GloriousEremite
Junior Poster in Training
65 posts since Jul 2006
Reputation Points: 108
Solved Threads: 14
 

Thank you very much for you help I haven't thought about GetlLastError before. Anyways, I found out that the code is totally correct but my bitmap file was corrupted. It is working now. But I might come back again on this Treeview control since I never used before

Thank you again.

nhandal
Newbie Poster
5 posts since Sep 2006
Reputation Points: 27
Solved Threads: 0
 

listen all. how can I use HIMAGELIST on listbox? I want to use HIMAGELIST on listbox because I want to move listbox items wherever I want.

lashatt2
Light Poster
36 posts since Oct 2009
Reputation Points: 5
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You