Solved

m_tree.SetImageList(LPDISPATCH newVal)

Posted on 2000-04-22
7
575 Views
Last Modified: 2013-11-20
Hi,
I am working with the TreeView ActiveX and having trouble using the above function. Here is what I think so far,

In order to set the image list for my m_treeCtrl, I must use:
m_treeCtrl.SetImageList(LPDISPATCH newValue). But I'm confused on what to pass to this function. I've added the ImageList ActiveX control to my app and have played aroud with the CPicture, CImage & CImages. The CImages has a function: Add(VARIANT* Index, VARIANT* Key, VARIANT* Picture), so I did this:
CPictureHolder pic;
pic.CreateFromIcon(IDI_ICON1);
pic.CreateFromIcon(IDI_ICON2);
CPicture picture(pic.GetPictureDispatch());

Now, I think I need to call:
m_images.Add(...), but get stuck on what I need to pass as variables, especially the VARIANT* Picture. Am I on the right track?.
0
Comment
Question by:Malek103197
  • 4
  • 3
7 Comments
 
LVL 3

Expert Comment

by:_mb_
ID: 2741349
Hi Malek,
I use an image list similar to this description:
At first I add a CImageList-member to the header file of my tree-control class:

CImageList m_imageList;

The images I get from a bitmap  resource(IDB_TREEIMAGE in my example).
The following lines show, how you can handle an imagelist for a tree control.
The last two parameters of CImageList::Create determine the count of images. Have a look at the description for it.
Here I add only one bitmap.

CBitmap bitmap;

m_imageList.Create(16, 16, ILC_MASK, 1, 1);
bitmap.LoadBitmap(IDB_TREEIMAGE);
m_imageList.Add(&bitmap, (COLORREF)0xFFFFFF);
      
m_TreeCtrl.SetImageList(&m_imageList, TVSIL_NORMAL);

0
 

Author Comment

by:Malek103197
ID: 2741650
Hi mb,

I am working with the TreeView ActiveX control, not the CTreeCtrl (from CWnd). I have successfully implemented the CTreeCtrl (from CWnd), but I am trying to work with the TreeView OCX. You may ask why am I struggling with the OCX when the CWnd class is easy to implement. The reason is that I am trying to get a grasp on how to work with ActiveX controls, in general, so I've decided to pursue the Treeview OCX. If you have time, try adding the TreeView OCX to an app. and try to get it working - I am stuck. Hope you can help.
0
 
LVL 3

Expert Comment

by:_mb_
ID: 2743763
hi malek,

I tried it in this way:

- I created a dialog based application.
- Then I added the the TreeView-control and the ImageList-control to my dialog.
- I used the class wizard to create member variables for the controls (m_Tree and m_imageList). VC++6 automatically generated IDispatch wrapper classes for TreeView-control, ImageList-control and some others.
- I used the property dialog of the ImageList-control and added an image. You can do this also programmatically but I havn't enough time to test it.
- The OnInitDialog() member of my dialog got the following code:

//Get an IDispatch pointer of the imagelist an attach it to the treeview
LPDISPATCH   lpd;
LPUNKNOWN    lpun = m_imageList.GetControlUnknown();

if( lpun && (SUCCEEDED(lpun->QueryInterface(IID_IDispatch,
     (LPVOID *)&lpd))) )
{
     m_Tree.SetImageList(lpd);
     lpd->Release();
}

//Add 2 entries to the treeview
 m_Tree.GetNodes().Add(NULL, COleVariant((short)1),
     COleVariant("R", VT_BSTR), COleVariant("Root", VT_BSTR),
     COleVariant((short)1), COleVariant((short)1));

m_Tree.GetNodes().Add(COleVariant("R", VT_BSTR), COleVariant((short)4),
     COleVariant("C1", VT_BSTR), COleVariant("Child1", VT_BSTR),
     COleVariant((short)1), COleVariant((short)1));


I hope, some notes of my comment can help you.
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

Author Comment

by:Malek103197
ID: 2754073
For mb:

Thanks for the help. It looks great but I have 2 known problems with it. First, when I try to SetImageList, a mesage pops up saying that I have to "initialize" the image list first before using it. Second, In the GetNodes().Add(...) it returns a CNode, but I don't know how to declare a CNode object. I tried using CreateDispatch, but am still a bit confused - any help on this would be great.

0
 
LVL 3

Expert Comment

by:_mb_
ID: 2754493
I got the same message before I added an image. Open the property dialog for the ImageList-control and insert a picture (tab 'images' or 'pictures'). Then it should work.

You don't need to do anything for declaration a CNode object. The Add-function creates the nodes and you get and can use these objects:

// get a node object
CNode ndRoot = m_Tree.GetNodes().Add(NULL, COleVariant((short)1),
     COleVariant("R", VT_BSTR), COleVariant("Root", VT_BSTR),
     COleVariant((short)1), COleVariant((short)1));

//get a node object, another way
CNode ndRoot = m_Tree.GetNodes().GetItem(COleVariant("R", VT_BSTR));

// example for usage
CString sRoot = ndRoot.GetText();
0
 

Author Comment

by:Malek103197
ID: 2775626
Hi mb,

Sorry for the delay in reponding. Even when I a set a couple of images (pictures) I still get "Image List must be initialized before it can be used", and then sometimes I get an unhandled exception. What do I put in for the "key" and "tag" values for the images?. Thanks.
0
 
LVL 3

Accepted Solution

by:
_mb_ earned 200 total points
ID: 2776384
Hi malek,

the "key"/"tag" values need an arbitrary string, that starts with a letter character. But my example also works, if they are empty.
If you post your email-adress to mbmun@web.de, I can send my sample project to you.
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Separate into files by filename 12 82
notReplace  challenge 53 125
difference between String.subString() and String.subSequence() 6 194
Window placement 17 81
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
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.

785 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