Solved

Using TreeView control

Posted on 1998-12-28
1
268 Views
Last Modified: 2013-12-03
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
Comment
Question by:hge
1 Comment
 

Accepted Solution

by:
jmayfield earned 100 total points
ID: 1417759
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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question