Solved

m_tree.SetImageList(LPDISPATCH newVal)

Posted on 2000-04-22
7
567 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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
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…
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.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

706 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

12 Experts available now in Live!

Get 1:1 Help Now