Solved

Using TreeView control

Posted on 1998-12-28
1
264 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
Comment Utility
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

771 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now