Results 1 to 17 of 17

Thread: THe Usual: FindWindowEx

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2001
    Location
    Upstate NY
    Posts
    210

    Talking

    I know you guys have probably been asked this before, but i'd like to ask it now. What is the best was to get a handle? i use FindWindow to get the handle of the parent, and others have told me that i can use FindwindowEx to find children, but when i use FindWindowEx, it simply returns a 0 instead of a handle. What am I doing wrong?

  2. #2
    Guest
    Are you using the FindWindowEx API function the correct way?


    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 Sub Command1_Click()
    
        Dim hWin As Long
        hWin = FindWindowEx(0, 0, "SciCalc", "Calculator")
        If hWin <> 0 Then 
            MsgBox "Calculator's handle: " & hWin
        Else
            Msgbox "Calculator not found"
        End If
    
    End Sub

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Feb 2001
    Location
    Upstate NY
    Posts
    210

    oh

    I already know that, what i was asking was how i use any function to get the handle of a child, like the division button on the calculator
    < o >

  4. #4
    Guest
    FindWindowEx works from left to right, top to bottom.


    So here is the code to find the division button.


    Code:
    Dim scicalc As Long, button As Long
    scicalc = FindWindow("scicalc", vbNullString)
    button = FindWindowEx(scicalc, 0&, "button", vbNullString)
    button = FindWindowEx(scicalc, button, "button", vbNullString)
    button = FindWindowEx(scicalc, button, "button", vbNullString)
    button = FindWindowEx(scicalc, button, "button", vbNullString)
    button = FindWindowEx(scicalc, button, "button", vbNullString)
    button = FindWindowEx(scicalc, button, "button", vbNullString)
    button = FindWindowEx(scicalc, button, "button", vbNullString)
    button = FindWindowEx(scicalc, button, "button", vbNullString)
    button = FindWindowEx(scicalc, button, "button", vbNullString)
    button = FindWindowEx(scicalc, button, "button", vbNullString)
    button = FindWindowEx(scicalc, button, "button", vbNullString)
    button = FindWindowEx(scicalc, button, "button", vbNullString)
    button = FindWindowEx(scicalc, button, "button", vbNullString)
    button = FindWindowEx(scicalc, button, "button", vbNullString)
    button = FindWindowEx(scicalc, button, "button", vbNullString)
    button = FindWindowEx(scicalc, button, "button", vbNullString)
    button = FindWindowEx(scicalc, button, "button", vbNullString)

  5. #5
    Guest
    Matthew Gates:
    First of all, you don't need that much code to find the divide button. you can do it in one line like this:
    Code:
    button = FindWindowEx(SciCalc, 0&, "button", "/")
    Secondly, you don't need both FindWindow and FindWindowEx, because FindwindowEx can do the same thing.
    Code:
    scicalc = FindwindowEx(0, 0, "SciCalc", "Calculator")

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Feb 2001
    Location
    Upstate NY
    Posts
    210

    um, okay

    Above:

    code:--------------------------------------------------------------------------------Dim scicalc As Long, button As Long
    scicalc = FindWindow("scicalc", vbNullString)
    button = FindWindowEx(scicalc, 0&, "button", vbNullString)
    button = FindWindowEx(scicalc, button, "button", vbNullString)
    button = FindWindowEx(scicalc, button, "button", vbNullString)
    button = FindWindowEx(scicalc, button, "button", vbNullString)
    button = FindWindowEx(scicalc, button, "button", vbNullString)
    button = FindWindowEx(scicalc, button, "button", vbNullString)
    button = FindWindowEx(scicalc, button, "button", vbNullString)
    button = FindWindowEx(scicalc, button, "button", vbNullString)
    button = FindWindowEx(scicalc, button, "button", vbNullString)
    button = FindWindowEx(scicalc, button, "button", vbNullString)
    button = FindWindowEx(scicalc, button, "button", vbNullString)
    button = FindWindowEx(scicalc, button, "button", vbNullString)
    button = FindWindowEx(scicalc, button, "button", vbNullString)
    button = FindWindowEx(scicalc, button, "button", vbNullString)
    button = FindWindowEx(scicalc, button, "button", vbNullString)
    button = FindWindowEx(scicalc, button, "button", vbNullString)
    button = FindWindowEx(scicalc, button, "button", vbNullString)--------------------------------------------------------------------------------

    How do i know how many times to put that line? Is there an easy way or is it trial and error?
    < o >

  7. #7
    Guest
    It can be done much simpler by using this line.
    Code:
    button = FindWindowEx(SciCalc, 0&, "button", "/")

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Feb 2001
    Location
    Upstate NY
    Posts
    210

    um...ok

    okay, if i passed the last string, "/", as a null string would it still return the handle?
    < o >

  9. #9
    Guest
    For some reason, I cannot get Megatron's code to work.
    But using the code I gave...

    Code:
    Private Declare Function FindWindow Lib "user32" _
    Alias "FindWindowA" (ByVal lpClassName As String, _
    ByVal lpWindowName As String) As Long
    
    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 PostMessage Lib "user32" _
    Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg _
    As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    
    Private Const WM_LBUTTONDOWN = &H201
    Private Const WM_LBUTTONUP = &H202
    Private Const MK_LBUTTON = &H1
    
    
    
    Private Sub Command1_Click()
        
        Dim scicalc As Long, button As Long
        scicalc = FindWindow("scicalc", vbNullString)
        button = FindWindowEx(scicalc, 0&, "button", vbNullString)
        button = FindWindowEx(scicalc, button, "button", vbNullString)
        button = FindWindowEx(scicalc, button, "button", vbNullString)
        button = FindWindowEx(scicalc, button, "button", vbNullString)
        button = FindWindowEx(scicalc, button, "button", vbNullString)
        button = FindWindowEx(scicalc, button, "button", vbNullString)
        button = FindWindowEx(scicalc, button, "button", vbNullString)
        button = FindWindowEx(scicalc, button, "button", vbNullString)
        button = FindWindowEx(scicalc, button, "button", vbNullString)
        button = FindWindowEx(scicalc, button, "button", vbNullString)
        button = FindWindowEx(scicalc, button, "button", vbNullString)
        button = FindWindowEx(scicalc, button, "button", vbNullString)
        button = FindWindowEx(scicalc, button, "button", vbNullString)
        button = FindWindowEx(scicalc, button, "button", vbNullString)
        button = FindWindowEx(scicalc, button, "button", vbNullString)
        button = FindWindowEx(scicalc, button, "button", vbNullString)
        button = FindWindowEx(scicalc, button, "button", vbNullString)
        Msgbox "Clicking button with the hwnd of:  " & button
        PostMessage button, WM_LBUTTONDOWN, MK_LBUTTON, 0
        PostMessage button, WM_LBUTTONUP, MK_LBUTTON, 0
        
    End Sub

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Feb 2001
    Location
    Upstate NY
    Posts
    210

    okay, it's making sense =)

    Okay, the way above, i like better. It uses FindWindow and FindwindowEx, one last question. The code above has :


    button = FindWindowEx(scicalc, button, "button", vbNullString)

    over and over again, how do i find out how many times to put that line, or is it trial and error?
    < o >

  11. #11
    Guest
    Use this code. It's much shorter.
    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 Sub Command1_Click()
        Dim hCalc As Long
        hCalc = FindWindowEx(0, 0, "SciCalc", "Calculator")
        btn = FindWindowEx(hCalc, 0, "Button", "/")
        
        'Display hWnd
        MsgBox btn
    End Sub

  12. #12
    Guest
    Originally posted by Megatron
    Use this code. It's much shorter.
    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 Sub Command1_Click()
        Dim hCalc As Long
        hCalc = FindWindowEx(0, 0, "SciCalc", "Calculator")
        btn = FindWindowEx(hCalc, 0, "Button", "/")
        
        'Display hWnd
        MsgBox btn
    End Sub

    Msgbox btn 'returns 0 with Calculator opened

    Well, since you posted again Megatron, before I tried the code, I was thinking, it probably works for him, since he has the magikal touch (even though I did the same exact way and it wasn't working).

    But it's not working either.

  13. #13
    Guest

    Re: okay, it's making sense =)

    Originally posted by Rh0ads
    Okay, the way above, i like better. It uses FindWindow and FindwindowEx, one last question. The code above has :


    button = FindWindowEx(scicalc, button, "button", vbNullString)

    over and over again, how do i find out how many times to put that line, or is it trial and error?


    Refer to this line.


    Originally posted by Matthew Gates
    FindWindowEx works from left to right, top to bottom.

    Well...top to bottom, left to right .

  14. #14
    Guest
    Logically it makes sense. The last argument of FindwindowEx specifies the WindowName (text). "/" is the name of the divide button.

  15. #15

    Thread Starter
    Addicted Member
    Join Date
    Feb 2001
    Location
    Upstate NY
    Posts
    210

    okay

    Okay here's some code:

    Code:
    Dim a&
    Dim Button&
    a& = FindWindow("ThunderRT6FormDC", vbNullString)
    Button& = FindWindowEx(a&, 0, "ThunderRT6CommandButton", vbNullString)
    Button& = FindWindowEx(a&, Button&, "ThunderRT6CommandButton", vbNullString)
    MsgBox Button&
    Call Click_Button(Button)
    I have the Click_Button sub working fine, but when the message box comes up that is supossed to tell me the Handle of the button, it just gives me a zero. What am i doing wrong now?
    < o >

  16. #16
    Guest
    You can shorten your code by omitting the use for findWindow, because you can do the exact same thing with FindwindowEx (which you're using anyways).
    Code:
    FindWindow(0, 0, "ThunderRT6FormDC", vbNullString)
    Secondly, you don't need to use that many lines of code to find the button you want. Simply replace vbNullString, with the TEXt of the button. For example, if the Text is "Command1" then you would use:
    Code:
    Button& = FindWindowEx(a&, 0, "ThunderRT6CommandButton", "Command1")

  17. #17
    Guest
    That also may be the reason why it's not working, because since you may have more than one class of "ThunderRT6FormDC" open, windows s only searching one of them and not the other, thus you need to be more specific by specifiying the name of the window as well.
    Code:
    a& = FindWindow("ThunderRT6FormDC", "My_Window_Caption")

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