Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 617
  • Last Modified:

m_tree.SetImageList(LPDISPATCH newVal)

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
Malek103197
Asked:
Malek103197
  • 4
  • 3
1 Solution
 
_mb_Commented:
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
 
Malek103197Author Commented:
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
 
_mb_Commented:
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
Malek103197Author Commented:
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
 
_mb_Commented:
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
 
Malek103197Author Commented:
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
 
_mb_Commented:
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now