Results 1 to 10 of 10
  • Thread Tools
  1. Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Form Window handle

    How can I get the window handle (for use with APIs) of the current Word userform?
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  2. JustCallMeAl
    #2
    Guest

    Re: Form Window handle

    This may be of help.

    <pre>Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
    (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

    Declare Function LockWindowUpdate Lib "user32" _
    (ByVal hWnd As Long) As Long


    Public Function ThisHandle() As Long

    Dim hWndXl As Long

    ' Necessary because most Office applications can handle multiple instances
    Application.Caption = "New Caption Supplied by Program"

    ' Calling the below API gives the hWnd to ThisHandle (the function)
    ThisHandle = FindWindow("OpusApp", Application.Caption)

    ' Set the original caption back
    Application.Caption = Empty


    End Function


    Public Sub LockWindow(hWnd As Long, blnValue As Boolean)
    'This function is called by the following lines:
    ' LockWindow ThisWindow True
    ' LockWindow ThisWindow False

    If blnValue Then
    ' Locks the window
    LockWindowUpdate hWnd
    Else
    ' Unlocks the window
    LockWindowUpdate 0
    End If

    End Sub


    </pre>


  3. Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Form Window handle

    Al, Thanks, but this does not give me the window handle of a Word userform. It give the App (Word) handle. Any other ideas?
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  4. JustCallMeAl
    #4
    Guest

    Re: Form Window handle

    Ok, how about....

    <pre>FindWindowEx

    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</pre>


  5. Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Form Window handle

    Look where I was when your email hit:

    <A target="_blank" HREF=http://www.vbapi.com/ref/f/findwindowex.html>http://www.vbapi.com/ref/f/findwindowex.html</A>

    Thanks! I'm with you on this one...
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  6. Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Form Window handle

    Al,

    I've got it using FindWindow(). Turns out it's not that complicated after all.

    I had not realized that the classname (Parameter 1) can be nullstring and if so, the window search entails the current app's windows (my understandint -- maybe it means "seach ALL windows" -- heck, I can't understand these geeks who put these things together. Which brings up another issue --later). So, this does the trick

    hWinChild = Findwindow(vbNullString, "My Form Name")

    Voila!

    I wanted the window handle in order to position the very cool SHBrowseForFolder dialog relative to the userform window, not the App window (Word). Success.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  7. JustCallMeAl
    #7
    Guest

    Re: Form Window handle

    Glad that it worked out.

    There is some important information in this thread. I would suspect that getting a form handle via VBA would be something that is needed now and again. Thanks for posting the "solution."

  8. Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Form Window handle

    This was a fun thread. Especially since it all worked toward a solution (that was one line of CODE!). You should have seen my head pounding last night. I left work with a big ol' headache.

    I think the Lounge folks really ought to consider a code library like so many other board/forums etc. have. Talk about one-stop shopping. I know seaching should get you what you need, but it's not clear we have any sort of code library available here.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  9. Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Form Window handle

    Kevin.

    Try this :-

    Private Declare Function GetActiveWindow Lib "user32" () As Long

    then

    hWnd = GetActiveWindow()

    Andrew C

  10. Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Form Window handle

    And where were you during the heat of the battle.

    Just letting me pound this one out, huh? Wise guy.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

Posting Permissions

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