Solved

m_tree.SetImageList(LPDISPATCH newVal)

Posted on 2000-04-22
7
582 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
[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
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.

732 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