0

Recently Started working on MSComctlLib TreeView and ImageList

want to figure out how to use images in my TreeView, also how to set background to my TreeView object;

using C# windows application, writing addon for sap b1 which has ActiveX support.

so what I did
loaded MSComctlLib.TreeCtrl.2 object
loaded MSComctlLib.ImageListCtrl.2 object

code snippet for ImageList

var type = Type.GetTypeFromProgID("MSComctlLib.ImageListCtrl.2");
var inst = Activator.CreateInstance(type) as MSComctlLib.ImageList;

var image = Image.FromFile("Images/folder.bmp"); //tried with .png as well

then created IPictureDisp object using Microsoft.VisualBasic.Compatibility.VB6 namespace

var imgObj = Support.ImageToIPictureDisp(image);
inst.ListImages.Add(ref ind, ref key, imgObj1); //here getting error

but when I'm trying to add imgObj to ListImages getting

Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED)) at MSComctlLib.IImages.Add(Object& Index, Object& Key, Object& Picture)

I want to create ListImage instance to use it in my TreeView ImageList. set background of TreeView but can't figure out how to make all this work.

looked in http://www.virtualsplat.com/tips/visual-basic-treeview-control.asp

Also tried using Resource file with images. This way getting invalid picture.

object ind = 1;
object key = "1";
inst.ListImages.Add(ref ind, ref key, Properties.Resource.folder_bmp);

P.S. Is there any other alternative to ImageToIPictureDisp? because this library is already obsolete and working only on 32bit processes

xurca
  • 2,426
  • 3
  • 24
  • 29
  • There is no point in using these ancient VB6 wrappers anymore. Use the .NET ImageList, Bitmap and TreeView classes instead. – Hans Passant Apr 10 '20 at 18:00
  • @HansPassant I know, but problem is with SAP Addons. That have only ActiveX interface for extending controls, or adding more. Also wrote question https://stackoverflow.com/questions/61060831/create-custom-activex-controls-for-sap-b1 Got stuck with COM event binding, if you take a look would be great. – xurca Apr 10 '20 at 18:13
  • @HansPassant as I understand it's possible to make .Net component COM visible. reference it to my addon and work with this component, only porblem is exposing events where I need to implement IConnectionPointContainer and IConnectionPoint to make possible handling events. Is it the way I should continue? – xurca Apr 10 '20 at 18:36

0 Answers0