How to Get the Guid, CLSID, of a Control on a Form in Code by vb6
I want to create controls dynamically.But I don't know, the GUID of each control
What code can control all the objects on the computer all out.
like Set oControl = Me.Controls.Add("Shell.Explorer.2", "Web1")
Code:
Dim WithEvents oControl As VBControlExtender
'After the declaration with event declaration, you can find that the object appears in the drop-down box of the object in the upper left corner of the code window, that is, the object has events or methods, and its events include DragDrop, DragOver, LostFocus, GotFocus , ObjectEvent and Validate, where ObjectEvent is a general event capture.
Private Sub Command1_Click()
LoadControl
End Sub
Private Sub Command2_Click()
LoadControl2
End Sub
Private Sub LoadControl()
Set oControl = Controls.Add("Prj1.Usercontrol1", "MyButton")
'Set oControl = Controls.Add("VB.CommandButton", "MyButton")
oControl.Visible = True
oControl.Top = Command1.Top + Command1.Height + 50
End Sub
Private Sub LoadControl2()
Set oControl = Me.Controls.Add("Shell.Explorer.2", "Web1")
oControl.Width = 400 * Screen.TwipsPerPixelX
oControl.Height = 300 * Screen.TwipsPerPixelY
oControl.Top = Command1.Top + Command1.Height + 50
oControl.Left = Me.ScaleWidth / 2
oControl.Visible = True
oControl.Silent = True
oControl.Navigate "https://www.baidu.com"
End Sub
Private Sub oControl_ObjectEvent(Event1 As EventInfo)
Select Case Event1.Name
Case "Click" 'Click事件 '您可以添加处理Click事件代码
MsgBox "You Click MyButton!"
Case "MouseDown"
Me.Caption = "MouseDown-" & Now
Case Else ' 其他事件
' Handle unknown events here.
'Debug.Print "事件:" & Event1.Name & ",参数个数:" & Event1.EventParameters.Count
Debug.Print "Event Name:" & Event1.Name & ",EventParameters Count:" & Event1.EventParameters.Count
End Select
End Sub
Last edited by xiaoyao; May 5th, 2021 at 08:23 PM.
Re: How to Get the Guid, CLSID, of a Control on a Form in Code by vb6
Originally Posted by xiaoyao
I WANT GET GUID LIKE DATAGRID,EXCEL APPLICATION, vsflexgrid control when exe is running,get object guid
Add a reference to Typelib Information
Code:
Dim iTLB As InterfaceInfo
Dim o As Object
Dim s As String
Set o = CreateObject("Excel.Application")
Set iTLB = TLI.InterfaceInfoFromObject(o)
o.quit
s = "Excel: " & iTLB.Guid & vbCrLf
Set iTLB = TLI.InterfaceInfoFromObject(MSFlexGrid1)
s = s & "MSFlexGrid: " & iTLB.Guid & vbCrLf
Set iTLB = TLI.InterfaceInfoFromObject(DataGrid1)
s = s & "DataGrid: " & iTLB.Guid
MsgBox s
PS: it doesn't work with controls compiled.
Last edited by Eduardo-; May 8th, 2021 at 06:00 AM.