Inserts a new item of ActiveX type, and returns a handle to the newly created item.
Type | Description | |||
Parent as HITEM | A long expression that indicates the handle of the parent item where the ActiveX will be inserted. If the argument is 0 then the InsertControlItem property inserts the ActiveX control as a root item. If the Parent property is referring a locked item ( ItemLocked property ), the InsertControlItem property doesn't insert a new child ActiveX, instead insert the ActiveX control to the locked item that's specified by the Parent property. | |||
ControlID as String | A string expression that can be formatted as follows: a prog ID, a CLSID, a URL, a reference to an Active document , a fragment of HTML. | |||
License as Variant | A string expression that indicates the runtime license key, if it is required. An empty string, if the control doesn't require a runtime license key. |
Return | Description | |||
HITEM | A long expression that indicates the handle of the newly created item. |
The control supports ActiveX hosting, so
you can insert any ActiveX component. The ControlID must be formatted in one of the following ways:Once that an item of ActiveX type has been added you can get the OLE control created using the ItemObject property. To check if an item contains an ActiveX control you can use ItemControlID property. To change the height of an ActiveX item you have to use ItemHeight property. When the group contains at least an item of ActiveX type, it is recommend to set ScrollBySingleLine property of group to true. Events from contained components are fired through to your program using the exact same model used in VB6 for components added at run time ( See ItemOleEvent event, OleEvent and OleEventParam ). For instance, when an ActiveX control fires an event, the control forwards that event to your container using ItemOleEvent event of the control.
The following sample adds dynamically an ExplorerTree ActiveX Control and a Microsoft Calendar Control:
With ExplorerTree1.Groups(0) Dim hExplorerTree As HITEM hExplorerTree = .Items.InsertControlItem(.Items(0), "Exontrol.ExplorerTree") .Items.ItemHeight(hExplorerTree) = 212 With .Items.ItemObject(hExplorerTree) With .Groups.Add("Inside Group") With .Items .AddItem "One" .AddItem "Two" .AddItem "Three" End With End With End With Dim hCalc As HITEM hCalc = .Items.InsertControlItem(, "MSCal.Calendar") With .Items.ItemObject(hCalc) .ShowTitle = False .ShowDateSelectors = False End With End With
The following sample shows how to handle any event that a contained ActiveX fires:
Private Sub ExplorerTree1_ItemOleEvent(ByVal Group As EXPLORERTREELibCtl.IGroup, ByVal Item As EXPLORERTREELibCtl.HITEM, ByVal Ev As EXPLORERTREELibCtl.IOleEvent) On Error Resume Next Dim i As Long Debug.Print "The " & Ev.Name & " was fired. " If Not (Ev.CountParam = 0) Then Debug.Print "The event has the following parameters: " For i = 0 To Ev.CountParam - 1 Debug.Print " - " & Ev(i).Name & " = " & Ev(i).Value Next End If End Sub
Some of ActiveX controls requires additional window styles to be added to the conatiner window. For instance, the Web Brower added by the Group.Items.InsertControlItem(, "https://www.exontrol.com") won't add scroll bars, so you have to do the following:
First thing is to declare the WS_HSCROLL and WS_VSCROLL constants at the top of your module:
Private Const WS_VSCROLL = &H200000 Private Const WS_HSCROLL = &H100000
Then you need to to insert a Web control use the following lines:
Dim hWeb As HITEM hWeb = Group.Items.InsertControlItem(, "https://www.exontrol.com") Group.Items.ItemHeight(hWeb) = 196
Next step is adding the AddItem event handler:
Private Sub ExplorerTree1_AddItem(ByVal Group As EXPLORERTREELibCtl.IGroup, ByVal Item As EXPLORERTREELibCtl.HITEM) If (Group.Items.ItemControlID(Item) = "https://www.exontrol.com") Then ' Some of controls like the WEB control, requires some additional window styles ( like WS_HSCROLL and WS_VSCROLL window styles ) ' for the window that host that WEB control, to allow scrolling the web page Group.Items.ItemWindowHostCreateStyle(Item) = Group.Items.ItemWindowHostCreateStyle(Item) + WS_HSCROLL + WS_VSCROLL End If End Sub
If somehow the InsertItemControl wasn't able to create your ActiveX on some Windows platforms, and you don't know why, you can use the following code to make sure that ActiveX control can be created properly by using ( the sample is trying to add a new Microsoft RichText ActivX control into your form):
Controls.Add "RICHTEXT.RichtextCtrl", "rich"