Results 1 to 8 of 8

Thread: How to Get the Guid, CLSID, of a Control on a Form in Code by vb6

  1. #1

    Thread Starter
    Taking a Break
    Join Date
    Jan 2020
    Posts
    1,340

    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.

  2. #2
    Frenzied Member
    Join Date
    Feb 2003
    Posts
    1,347

    Re: How to Get the Guid, CLSID, of a Control on a Form in Code by vb6


  3. #3

    Thread Starter
    Taking a Break
    Join Date
    Jan 2020
    Posts
    1,340

    Re: How to Get the Guid, CLSID, of a Control on a Form in Code by vb6

    Quote Originally Posted by Peter Swinkels View Post
    I WANT GET GUID LIKE DATAGRID,EXCEL APPLICATION, vsflexgrid control when exe is running,get object guid

  4. #4
    PowerPoster
    Join Date
    Feb 2017
    Posts
    3,234

    Re: How to Get the Guid, CLSID, of a Control on a Form in Code by vb6

    Quote Originally Posted by xiaoyao View Post
    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.
    Attached Files Attached Files
    Last edited by Eduardo-; May 8th, 2021 at 06:00 AM.

  5. #5
    Frenzied Member
    Join Date
    Feb 2003
    Posts
    1,347

    Re: How to Get the Guid, CLSID, of a Control on a Form in Code by vb6

    @xiaoyao, okay I misunderstood your question. Sorry.

  6. #6
    Hyperactive Member
    Join Date
    Jun 2015
    Posts
    449

    Re: How to Get the Guid, CLSID, of a Control on a Form in Code by vb6

    All of the GUID information is in the registry.

    Add Reference (ActiveX Dlls):
    https://github.com/dzzie/addins/blob...dRefs.frm#L166

    Add Component (OCXs):
    https://github.com/dzzie/addins/blob...dRefs.frm#L255
    Last edited by dz32; May 8th, 2021 at 02:27 PM.

  7. #7

    Thread Starter
    Taking a Break
    Join Date
    Jan 2020
    Posts
    1,340

    Re: How to Get the Guid, CLSID, of a Control on a Form in Code by vb6

    Quote Originally Posted by dz32 View Post
    All of the GUID information is in the registry.

    Add Reference (ActiveX Dlls):
    https://github.com/dzzie/addins/blob...dRefs.frm#L166

    Add Component (OCXs):
    https://github.com/dzzie/addins/blob...dRefs.frm#L255
    very good ,thank you

  8. #8

    Thread Starter
    Taking a Break
    Join Date
    Jan 2020
    Posts
    1,340

    Re: How to Get the Guid, CLSID, of a Control on a Form in Code by vb6

    Quote Originally Posted by Peter Swinkels View Post
    @xiaoyao, okay I misunderstood your question. Sorry.
    Itís okay, thanks for sharing and learning together

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width