Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 275
  • Last Modified:

Using TreeView control

If I use a TreeView control the bitmaps won't load. Next is the code I use to achieve on another:

Header file:

#include <commctrl.h>   // includes the common control header

#define MAXTREEVIEWS         32
#define ID_TREEVIEW          1000

#define BMP_NONE             0
#define BMP_FOLDER           1
#define BMP_FOLDER_SELECTED  2

#define NUM_BITMAPS          2
#define BMP_HEIGHT           16
#define BMP_WIDTH            16

Following is the code-fragment that loads the bitmaps:

  // Initialize the tree view window.
  // First create the image list you will need.
  hIml = ImageList_Create(BMP_WIDTH       // bitmap width
                         ,BMP_HEIGHT      // bitmap height
                         ,0               // creation flags
                         ,NUM_BITMAPS     // number of images
                         ,0               // amount this list can grow
                         );

  // Load the bitmaps and add them to the image list.
  hBmp = LoadBitmap(hInstance
                   ,MAKEINTRESOURCE(BMP_FOLDER)
                   );
  if (hBmp == NULL){
    MessageBox(hWndParent
              ,"Bitmap not loaded!!!"
              ,"createTreeView()..."
              ,MB_OK
              );
  }
   
  idxFolder = ImageList_Add(hIml        // handle to imagelist
                           ,hBmp        // handle of bitmap to add
                           ,NULL        // handle of bitmap mask
                           );
  hBmp = LoadBitmap(hInstance
                   ,MAKEINTRESOURCE(BMP_FOLDER_SELECTED)
                   );
  idxFolderSelected = ImageList_Add(hIml
                                   ,hBmp
                                   ,NULL
                                   );

Following is the content of the resource file:

#include "vdgtreeview.h"


BMP_FOLDER BITMAP DISCARDABLE "bmp_folder.bmp"
BMP_FOLDER_SELECTED BITMAP DISCARDABLE "bmp_folder_selected.bmp"

Can anybody tell me what's wrong?

Thanx
Henk
0
hge
Asked:
hge
1 Solution
 
jmayfieldCommented:
I can't believe that no one has given you an answer. We can work this one out together until you get it working. I have done what you are doing many times.

You might want to change the following params in your:
ImageList_Create(BMP_WIDTH       // bitmap width
                         ,BMP_HEIGHT      // bitmap height
                         ,0               // creation flags
                         ,NUM_BITMAPS     // number of images
                         ,0               // amount this list );

My third param = ILC_MASK | ILC_COLOR4.
My fifth param = 50;

But that is not the problem. Here is the problem:

You are creating an imagelist and then not associating it with your treeview. Here are the following steps that you need to do if you want your tree view to have icons.

1. Create an imagelist.
2. Set the imagelist of the tree control to that Imagalist using TVM_SETIMAGELIST. In a treeview there are two different imagelists. One for normal state and another for when it is not selected not focused. Most of the time, I pass in TVSIL_NORMAL for TVM_SETIMAGELIST.
3. Add the images to the treeview (which will in turn add them to the imagelist) by sending TVM_INSERTITEM to the treeview with the flag TVIF_IMAGE.

I hope that this helps out. If you have further questions just write back.

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now