Solved

m_tree.SetImageList(LPDISPATCH newVal)

Posted on 2000-04-22
7
571 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Window placement 17 77
twoTwo  challenge 35 96
NotAlone Challenge 20 80
matchUp  challenge 9 94
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

864 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

19 Experts available now in Live!

Get 1:1 Help Now