Page 1 of 2 12 LastLast
Results 1 to 40 of 52

Thread: [RESOLVED] Getting hWnd from VBIDE.Window

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2012
    Posts
    1,253

    Resolved [RESOLVED] Getting hWnd from VBIDE.Window

    Hi folks...

    I'm in the process of writing (well, playing around, more like) an IDE addin, and I'd like to know if there's an easy way of getting the hWnd of a VBIDE.Window object.

    Anybody know how to do this?

    I stumbled across these;

    Private Declare Function WindowFromAccessibleObject Lib "oleacc" (ByVal pacc As IAccessible, pHwnd As Long) As Long
    Private Declare Function IUnknown_GetWindow Lib "shlwapi" Alias "#172" (ByVal pIUnk As IUnknown, ByVal hwnd As Long) As Long

    as a supposed way of getting the hWnd of a VBA Userform, but had no luck in applying this technique to my situation.

    Ideas?
    If you don't know where you're going, any road will take you there...

    My VB6 love-children: Vee-Hive and Vee-Launcher

  2. #2
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,995

    Re: Getting hWnd from VBIDE.Window

    In the add-in:

    Code:
        Dim c As Long
        
        For c = 1 To VBInstance.Windows.Count
            Debug.Print VBInstance.Windows(c).hWnd
        Next
    VBInstance is the object variable set in the AddinInstance_OnConnection procedure of the default add-in code.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2012
    Posts
    1,253

    Re: Getting hWnd from VBIDE.Window

    That's the first thing I tried, having read that .hWnd is a 'hidden' property of the Window object. But the hWnd's are all reported as 0. My code (inside my UserDocument):

    Code:
    Dim W As VBIDE.Window
       
       For Each W In gVBInstance.Windows
          If W.Visible Then
             Select Case W.Type
                Case vbext_wt_CodeWindow  
                      'blah blah
                Case vbext_wt_Designer
                      'blah blah
                Case vbext_wt_Browser 'Object Browser
                      'blah blah
                Case Else
                      'blah blah
             End Select
             Debug.Print W.hWnd, W.Caption
          End If
       Next W
    All the expected windows are there, by the way, as evidenced by the W.Captions
    Last edited by ColinE66; Jan 4th, 2021 at 05:14 AM.
    If you don't know where you're going, any road will take you there...

    My VB6 love-children: Vee-Hive and Vee-Launcher

  4. #4
    Fanatic Member
    Join Date
    Jan 2015
    Posts
    596

    Re: Getting hWnd from VBIDE.Window

    you can download the sources from VBIDEUtils, it can inspire you

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2012
    Posts
    1,253

    Re: Getting hWnd from VBIDE.Window

    Quote Originally Posted by Thierry69 View Post
    you can download the sources from VBIDEUtils, it can inspire you
    Hi Thierry, I already looked through all the Add-In code I could find, and did not encounter a method for doing this...
    If you don't know where you're going, any road will take you there...

    My VB6 love-children: Vee-Hive and Vee-Launcher

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2012
    Posts
    1,253

    Re: Getting hWnd from VBIDE.Window

    Further info....

    Debug.print gVBInstance.MainWindow.hWnd - returns a non-zero value

    Debug.print gVBInstance.ActiveWindow.hWnd - returns zero
    If you don't know where you're going, any road will take you there...

    My VB6 love-children: Vee-Hive and Vee-Launcher

  7. #7
    Frenzied Member
    Join Date
    Jun 2015
    Posts
    1,053

    Re: Getting hWnd from VBIDE.Window

    using EnumChildWindows from the top level IDE window yielded the attached images below, then enuming the children of
    a VBAWindow yielded some more hwnds but nothing of a separate embedded edit type control.

    I guess this means the code window edit control is custom drawn directly on the form hdc ?

    I have not had any luck sending messages to the code windows. I tried standard edit and rtf messages
    which did not seem to be honored.

    The closest I came was the ability to clear the immediate window. (Not 100% reliable
    I have had it blank out a code window on rare occasion.)

    Code:
    Sub ClearImmediateWindow()
        On Error Resume Next
        Dim oWindow As VBIDE.Window
        Set oWindow = VBInstance.ActiveWindow
        VBInstance.Windows("Immediate").SetFocus
        SendKeys "^{Home}", True   
        SendKeys "^+{End}", True
        SendKeys "{Del}", True
        oWindow.SetFocus
    End Sub
    
    Sub SetImmediateText(text As String)
        On Error Resume Next
        Dim oWindow As VBIDE.Window
        Dim saved As String
        Dim s As Date
        
        If Len(text) = 0 Then Exit Sub
        
        ClearImmediateWindow
        Clipboard.Clear
        Clipboard.SetText text
      
        VBInstance.Windows("Immediate").SetFocus
        SendKeys "^v", False 'True
    end sub
    Attached Images Attached Images   
    Last edited by dz32; Jan 4th, 2021 at 08:35 AM.

  8. #8

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2012
    Posts
    1,253

    Re: Getting hWnd from VBIDE.Window

    Thanks dz, but I was hoping to avoid that kind of approach, in case of window-name collisions, and the potential for captions being different under different language settings...
    If you don't know where you're going, any road will take you there...

    My VB6 love-children: Vee-Hive and Vee-Launcher

  9. #9
    PowerPoster
    Join Date
    Feb 2017
    Posts
    4,995

    Re: Getting hWnd from VBIDE.Window

    Quote Originally Posted by ColinE66 View Post
    But the hWnd's are all reported as 0.
    I see.

  10. #10
    Frenzied Member
    Join Date
    Jun 2015
    Posts
    1,053

    Re: Getting hWnd from VBIDE.Window

    step 1 find the handle somehow
    step 2 make sure you can do something useful with it

    second part has not been as expected.

  11. #11
    Fanatic Member Episcopal's Avatar
    Join Date
    Mar 2019
    Location
    Brazil
    Posts
    547

    Re: Getting hWnd from VBIDE.Window

    Code:
    Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
    Private Declare Function GetWindow Lib "user32" (ByVal hWnd As Long, ByVal wCmd As Long) As Long
    Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
    Private Declare Function IsWindowVisible Lib "user32" (ByVal hWnd As Long) As Long
    
        Dim WindowhWnd As Long
        Dim Buff As String * 255
        Dim DeskTophWnd As Long
        
        DeskTophWnd = VBInstance.MainWindow.hWnd
        WindowhWnd = GetWindow(DeskTophWnd, 5)
        
        Do While (WindowhWnd <> 0)
            GetWindowText WindowhWnd, Buff, 255
            If (Trim(Buff) <> "") And (IsWindowVisible(WindowhWnd) > False) Then
                MsgBox WindowhWnd, , Buff
            End If
            WindowhWnd = GetWindow(WindowhWnd, 2)
            Debug.Print WindowhWnd
        Loop
    Some untitled windows appear.

    www.vbforums.com/showthread.php?866639-RESOLVED-Get-List-Of-All-Visible-Windows-WinTitle-and-Hwnd
    Last edited by Episcopal; Jan 8th, 2021 at 08:25 PM.

  12. #12

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2012
    Posts
    1,253

    Re: Getting hWnd from VBIDE.Window

    Hi Episcopal,

    Yes, that's one way, of course, but I was wondering if it was possible to do it without looping through all the windows. Thanks for taking an interest, anyway...
    If you don't know where you're going, any road will take you there...

    My VB6 love-children: Vee-Hive and Vee-Launcher

  13. #13

  14. #14

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2012
    Posts
    1,253

    Re: Getting hWnd from VBIDE.Window

    Awesome. Thanks so much...

    I did have a try using GetMem4, but couldn't get it working. Then again, I didn't have that + &H1C. What is that for?

    Thanks, again...

    EDIT: Actually, thinking about it, I didn't try my PutMem4 code compiled, so it would never have worked anyway!
    Last edited by ColinE66; Jan 21st, 2021 at 08:05 AM.
    If you don't know where you're going, any road will take you there...

    My VB6 love-children: Vee-Hive and Vee-Launcher

  15. #15
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,120

    Re: Getting hWnd from VBIDE.Window

    Quote Originally Posted by ColinE66 View Post
    Then again, I didn't have that + &H1C. What is that for?
    It's the secret sauce! :-))

    Otherwise you could use CopyMemory API to access Window object's internal state as well -- makes no difference.

    cheers,
    </wqw>

  16. #16

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2012
    Posts
    1,253

    Re: [RESOLVED] Getting hWnd from VBIDE.Window

    Aah, secret sauce. Of course. From now on, whenever I encounter any bugs in my programs, I'll just throw-in an &H1C.

    EDIT: Actually, &H2A seems more appropriate.
    Last edited by ColinE66; Jan 21st, 2021 at 08:21 AM.
    If you don't know where you're going, any road will take you there...

    My VB6 love-children: Vee-Hive and Vee-Launcher

  17. #17

  18. #18

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2012
    Posts
    1,253

    Re: [RESOLVED] Getting hWnd from VBIDE.Window

    Thanks for posting the explanation; do you have any similar insights into how to get the icons for those windows as all of the usual approaches fail. Or am I pushing my luck? Currently, I am just getting the icon associated with the file type that the VBWindow represents, which works, but it feels like there should be a better way...
    If you don't know where you're going, any road will take you there...

    My VB6 love-children: Vee-Hive and Vee-Launcher

  19. #19

  20. #20

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2012
    Posts
    1,253

    Re: [RESOLVED] Getting hWnd from VBIDE.Window

    Hi again trick,

    The problem is, that the usual approaches like

    hIcon=SendMessage(hWnd, WM_GETICON, 0, 0)
    hIcon=GetClassLong(hwnd, GCL_HICONSM)

    all return 0 for the VBIDE windows and WinSpy confirms that there is no icon available for those hWnd's. And yet, there they are, visible in the top left corner!

    Because I cannot currently get these icons, my addin code is using the ones that relate to the VBComponent type; so, for example, if it's a Class module, I am using the icon associated with the .cls extension, which I obtain via SHGetFileInfo.

    But I'd really prefer to get the icon that the IDE is displaying, if I can. I was wondering if, perhaps, the icon handles are 'hidden' (like the hWnd's are), and that you could tell me the 'magic' offset?

    Thanks...
    If you don't know where you're going, any road will take you there...

    My VB6 love-children: Vee-Hive and Vee-Launcher

  21. #21

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2012
    Posts
    1,253

    Re: [RESOLVED] Getting hWnd from VBIDE.Window

    My bad. I can actually get the icons via SendMessage(hWnd, WM_GETICON, ICON_SMALL, 0&)

    Don't know what stupidity I was possessed by when I first tried, but I had another go and it worked just fine...

    This thread is well and truly resolved.
    If you don't know where you're going, any road will take you there...

    My VB6 love-children: Vee-Hive and Vee-Launcher

  22. #22
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,746

    Re: [RESOLVED] Getting hWnd from VBIDE.Window

    form1.caption="123123456"hwnd=findwindow(123123456,like this)

  23. #23

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2012
    Posts
    1,253

    Re: [RESOLVED] Getting hWnd from VBIDE.Window

    And what if I have two projects open, as a Project Group, and they each have a form with the same caption?
    If you don't know where you're going, any road will take you there...

    My VB6 love-children: Vee-Hive and Vee-Launcher

  24. #24
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,746

    Re: [RESOLVED] Getting hWnd from VBIDE.Window

    title=form1.caption
    Form1.caption=“123123456”
    hwnd=findWindow(123123456
    form1.caption=title

  25. #25

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2012
    Posts
    1,253

    Re: [RESOLVED] Getting hWnd from VBIDE.Window

    I don't think you understand the problem. Imagine there were two identical forms on your screen, with the same caption, and the user clicked one. Which one did he click?
    If you don't know where you're going, any road will take you there...

    My VB6 love-children: Vee-Hive and Vee-Launcher

  26. #26
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,120

    Re: [RESOLVED] Getting hWnd from VBIDE.Window

    The idea of xiaoyao's code is that if Caption property is writable then you can temporaty change the Caption to a unique string (a GUID) then use FindWindow API to locate the hWnd before restoring the original Caption.

    Super hacky but can be used as a last resort until anything better comes up.

    cheers,
    </wqw.

  27. #27
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,746

    Re: [RESOLVED] Getting hWnd from VBIDE.Window

    you can save vba forms hwnd in ini file ,when forms load.
    so findwindow ,will get 2 hwnd,you will khnow what form from ini file

  28. #28

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2012
    Posts
    1,253

    Re: [RESOLVED] Getting hWnd from VBIDE.Window

    Quote Originally Posted by xiaoyao View Post
    you can save vba forms hwnd in ini file ,when forms load.
    so findwindow ,will get 2 hwnd,you will khnow what form from ini file
    Hence the question: How do I get the hWnd of a vba window!
    If you don't know where you're going, any road will take you there...

    My VB6 love-children: Vee-Hive and Vee-Launcher

  29. #29

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2012
    Posts
    1,253

    Re: [RESOLVED] Getting hWnd from VBIDE.Window

    Quote Originally Posted by wqweto View Post
    The idea of xiaoyao's code is that if Caption property is writable then you can temporaty change the Caption to a unique string (a GUID) then use FindWindow API to locate the hWnd before restoring the original Caption.

    Super hacky but can be used as a last resort until anything better comes up.

    cheers,
    </wqw.
    Yes, I guess that would work (but is horrible!). But my example was actually a poor illustration of what I'm actually doing. My addin is a tabstrip, and the user could be clicking on a tab, rather than a window. In that case, I need to know which code pane or designer window corresponds to that tab, so that I can send it an activate message.
    If you don't know where you're going, any road will take you there...

    My VB6 love-children: Vee-Hive and Vee-Launcher

  30. #30
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,746

    Re: [RESOLVED] Getting hWnd from VBIDE.Window

    get hwnd :vba code in excel forms:

    Code:
    Dim MyHwnd As Long
    Private Declare PtrSafe Function FindWindowA Lib "user32" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Private Sub UserForm_Initialize()
    Dim OldCaption As String
    Dim NewCaption As String
    NewCaption = "nowTime:" & Now
    OldCaption = Me.Caption
    Me.Caption = NewCaption
    MyHwnd = FindWindowA(vbNullString, NewCaption)
    Me.Caption = OldCaption & ",hwnd=" & MyHwnd
    End Sub
    code 2:
    Code:
    Private Type GUID
        Data1 As Long
        Data2 As Integer
        Data3 As Integer
        Data4(7) As Byte
    End Type
    
    Private Declare Function CoCreateGuid Lib "ole32.dll" (G As GUID) As Long
    Private Declare Function StringFromGUID2 Lib "ole32.dll" (G As GUID, _
        ByVal str As String, _
        ByVal cchMax As Long) As Long
    
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" ( _
        ByVal lpClassName As String, _
        ByVal lpWindowName As String) As Long
    
    Private Function GetGUID() As String
        Dim G As GUID
        Dim S As String
    
        S = String(76, vbNullChar)
        CoCreateGuid G
        StringFromGUID2 G, S, Len(S)
        S = StrConv(S, vbFromUnicode)
        GetGUID = S
    End Function
    
    Private Function GetUserFormHandle(ByVal UF As Object)
        Dim S As String
        Dim OrigCaption As String
    
        S = GetGUID()
        OrigCaption = UF.Caption
        UF.Caption = S
        GetUserFormHandle = FindWindow(vbNullString, S)
        UF.Caption = OrigCaption
    End Function
    
    Private Sub Label1_Click()
    
    End Sub
    
    Private Sub UserForm_Initialize()
    Dim MyHwnd As Long
    MyHwnd = GetUserFormHandle(Me)
    Me.Caption = "Window handle:" & MyHwnd & ",Hex:0x" + Hex(MyHwnd)
    End Sub
    code 3:
    Code:
    Private Declare Function IUnknown_GetWindow Lib "shlwapi.dll" (ByVal punk As IUnknown, ByRef phwnd As Long) As Long
    
    Function GetHwnd_Com() As Long
    IUnknown_GetWindow Me, GetHwnd_Com
    End Function
    code 4
    Code:
    Private Declare Function IUnknown_GetWindow Lib "shlwapi.dll" (ByVal punk As IUnknown, ByRef phwnd As Long) As Long
    
    Private Declare PtrSafe Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
    Private Declare PtrSafe Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
    
    Function GetWinText(Hwnd1 As Long) As String
    Dim s As String
    
    Dim TextLen As Long
    s = String(255, 0) ' 
    
    TextLen = GetWindowTextLength(Hwnd1) ' 
    GetWindowText Hwnd1, s, 256
    
    GetWinText = Left(s, TextLen) ' 
    End Function
    
    Sub ListAllUserFormsHwnd()
    Dim MyHwnd As Long
    
     Dim f As UserForm
     For Each f In UserForms
       IUnknown_GetWindow f, MyHwnd
       MsgBox "MyHwnd=" & MyHwnd & ",caption=" & GetWinText(myhwnd)
     Next
    Last edited by xiaoyao; Jan 25th, 2021 at 10:35 AM.

  31. #31

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2012
    Posts
    1,253

    Re: [RESOLVED] Getting hWnd from VBIDE.Window

    Quote Originally Posted by xiaoyao View Post
    get hwnd :vba code in excel forms:

    Code:
    Dim MyHwnd As Long
    Private Declare PtrSafe Function FindWindowA Lib "user32" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    Private Sub UserForm_Initialize()
    Dim OldCaption As String
    Dim NewCaption As String
    NewCaption = "nowTime:" & Now
    OldCaption = Me.Caption
    Me.Caption = NewCaption
    MyHwnd = FindWindowA(vbNullString, NewCaption)
    Me.Caption = OldCaption & ",hwnd=" & MyHwnd
    End Sub
    Yes, I get it, thanks - I just don't like it very much! Trick's solution is much better for my situation. Thanks for posting, though...

    By the way, a VBIDE.Window's caption is read-only, according to the Object Browser...
    If you don't know where you're going, any road will take you there...

    My VB6 love-children: Vee-Hive and Vee-Launcher

  32. #32

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2012
    Posts
    1,253

    Re: [RESOLVED] Getting hWnd from VBIDE.Window

    Quote Originally Posted by xiaoyao View Post

    code 2:
    Code:
    Private Sub UserForm_Initialize()
        Me.Caption = Me.Caption & ",hwnd=" & Application.ActiveWindow.Hwnd
    End Sub
    Application.ActiveWindow.Hwnd returns 0. See post #6
    If you don't know where you're going, any road will take you there...

    My VB6 love-children: Vee-Hive and Vee-Launcher

  33. #33
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,120

    Re: [RESOLVED] Getting hWnd from VBIDE.Window

    Quote Originally Posted by ColinE66 View Post
    By the way, a VBIDE.Window's caption is read-only
    Ooops, scratch this alt solution then.

    cheers,
    </wqw>

  34. #34

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2012
    Posts
    1,253

    Re: [RESOLVED] Getting hWnd from VBIDE.Window

    Quote Originally Posted by wqweto View Post
    Ooops, scratch this alt solution then.

    cheers,
    </wqw>
    Even if that property was writable, my addin works whilst in Run and Break mode and, at that point, you'd definitely get a Permission Denied error if using that technique. Even Trick's solution has that problem.

    I've given up on using the IDE Object model for that reason. Right now, I'm enumerating all the child windows of the MDI window (for MDI mode), and the relvant window classes for SDI mode.
    If you don't know where you're going, any road will take you there...

    My VB6 love-children: Vee-Hive and Vee-Launcher

  35. #35
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,746

    Re: [RESOLVED] Getting hWnd from VBIDE.Window

    Code:
    Private Declare Function IUnknown_GetWindow Lib "shlwapi.dll" (ByVal punk As IUnknown, ByRef phwnd As Long) As Long
    
    Function GetHwnd_Com() As Long
    IUnknown_GetWindow Me, GetHwnd_Com
    
    'IUnknown_GetWindow userform1, GetHwnd_Com
    'IUnknown_GetWindow userform2, GetHwnd_Com
    End Function
    Last edited by xiaoyao; Jan 25th, 2021 at 10:08 AM.

  36. #36

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2012
    Posts
    1,253

    Re: [RESOLVED] Getting hWnd from VBIDE.Window

    Isn't that more-or-less what I said I'd tried in post #1? Anyway, I tried your code, as below, and all the hWn'ds returned were 0. Did you test it before posting?

    Code:
    Private Declare Function IUnknown_GetWindow Lib "shlwapi.dll" (ByVal punk As IUnknown, ByRef phwnd As Long) As Long
    
    Private Sub Command1_Click()
    Dim CP As CodePane, hWnd As Long
    
       For Each CP In gVBInstance.CodePanes
          IUnknown_GetWindow CP.Window, hWnd
          Debug.Print hWnd 
       Next CP
     
    End Sub
    Last edited by ColinE66; Jan 25th, 2021 at 10:27 AM.
    If you don't know where you're going, any road will take you there...

    My VB6 love-children: Vee-Hive and Vee-Launcher

  37. #37
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,746

    Re: [RESOLVED] Getting hWnd from VBIDE.Window

    Code:
    Private Declare Function IUnknown_GetWindow Lib "shlwapi.dll" (ByVal punk As IUnknown, ByRef phwnd As Long) As Long
    
    Private Declare PtrSafe Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
    Private Declare PtrSafe Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
    
    Function GetWinText(Hwnd1 As Long) As String
    Dim s As String
    
    Dim TextLen As Long
    s = String(255, 0) ' 
    
    TextLen = GetWindowTextLength(Hwnd1) ' 
    GetWindowText Hwnd1, s, 256
    
    GetWinText = Left(s, TextLen) ' 
    End Function
    
    Sub ListAllUserFormsHwnd()
    Dim MyHwnd As Long
    
     Dim f As UserForm
     For Each f In UserForms
       IUnknown_GetWindow f, MyHwnd
       MsgBox "MyHwnd=" & MyHwnd & ",caption=" & GetWinText(myhwnd)
     Next
    End Sub
    Last edited by xiaoyao; Jan 25th, 2021 at 10:34 AM.

  38. #38

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2012
    Posts
    1,253

    Re: [RESOLVED] Getting hWnd from VBIDE.Window

    Quote Originally Posted by xiaoyao View Post
    Code:
    Private Declare Function IUnknown_GetWindow Lib "shlwapi.dll" (ByVal punk As IUnknown, ByRef phwnd As Long) As Long
    
    Sub ListAllUserFormsHwnd()
    Dim MyHwnd As Long
    
     Dim f As UserForm
     For Each f In UserForms
       IUnknown_GetWindow f, MyHwnd
       MsgBox "MyHwnd=" & MyHwnd
     Next
    End Sub
    I'm not intrested in UserForms; see my original question. I'm interested in VBIDE.Windows.
    If you don't know where you're going, any road will take you there...

    My VB6 love-children: Vee-Hive and Vee-Launcher

  39. #39
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,746

    Re: [RESOLVED] Getting hWnd from VBIDE.Window

    Code:
    Private Declare Function IUnknown_GetWindow Lib "shlwapi.dll" (ByVal punk As IUnknown, ByRef phwnd As Long) As Long
    
    Sub ListAllUserFormsHwnd()
    Dim MyHwnd As Long
    
     Dim c As Long
        
        For c = 1 To VBInstance.Windows.Count
          ' IUnknown_GetWindow  VBInstance.Windows(c),MyHwnd
          'msgbox "MyHwnd=" & MyHwnd
    MsgBox VBInstance.Windows(c).ActivePane.Application.ActiveWindow.hwnd
    
        Next 
    End Sub
    Last edited by xiaoyao; Jan 25th, 2021 at 10:46 AM.

  40. #40
    PowerPoster
    Join Date
    Jan 2020
    Posts
    3,746

    Re: [RESOLVED] Getting hWnd from VBIDE.Window

    Dim x As String
    Dim vbc As VBIDE.VBComponent
    For Each vbc In ThisWorkbook.VBProject.VBComponents
    If vbc.Type = vbext_ct_MSForm Then
    Debug.Print vbc.Name
    x = x & vbCr & vbc.Name
    End If
    Next vbc
    If x = "" Then
    MsgBox "No UserForms created."
    Exit Sub
    End If
    MsgBox x

Page 1 of 2 12 LastLast

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