Solved

Using TreeView control

Posted on 1998-12-28
1
270 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
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…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

636 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