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.

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.

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.

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.

Comments
Naughty naughty ... don't bump threads!
This article has been dead for over six months. Start a new discussion instead.