Results 1 to 7 of 7

Thread: [RESOLVED] Using FindWindow to access External Windows, need help with my process

Threaded View

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2010
    Location
    Gold Coast, Australia
    Posts
    43

    Resolved [RESOLVED] Using FindWindow to access External Windows, need help with my process

    I am using consecutive loops to search for a a sequence of windows and automate clicking command buttons but sometimes some random windows pop up in between the normal windows and my program gets stuck in a loop until it finds the window it's looking for.

    This is my code, is there a better way of doing this?

    Code:
    Private Sub cmdYes_Click()
        Dim hWndPriceWindow As Long
        Dim hWndPriceBtn As Long
        Dim hWndOkayBtn As Long
        Dim hWndDispenseWindow As Long
        Dim hWndDispenseBtn As Long
        
        'Find first popup window
        Do
            DoEvents
    
            If frmSettings.chkWildcard.Value = 0 Then
                hWndPriceWindow = FindWindow(vbNullString, frmSettings.txtS3.Text)
            Else
                hWndPriceWindow = FindWindowWild(frmSettings.txtS3.Text)
            End If
       
        Loop Until hWndPriceWindow <> 0
        
        Do
            DoEvents
            hWndPriceBtn = FindWindowEx(hWndPriceWindow, 0&, "Button", "&Yes")
        Loop Until hWndPriceBtn <> 0
    
        Do
            DoEvents
            PostMessage hWndPriceBtn, BM_CLICK, 0, ByVal 0&
        Loop Until IsWindow(hWndPriceWindow) = 0
    
        Do
            DoEvents
            hWndOkayBtn = FindWindowEx(hWndParent, 0&, "Button", "Okay")
        Loop Until hWndOkayBtn <> 0
    
        PostMessage hWndOkayBtn, BM_CLICK, 0, ByVal 0&
    
        ' Find second popup window
        Do
            DoEvents
            hWndDispenseWindow = FindWindow(vbNullString, "Dispense")
        Loop Until hWndDispenseWindow <> 0
    
        Do
            DoEvents
            hWndDispenseBtn = FindWindowEx(hWndDispenseWindow, 0&, "Button", "&Yes")
        Loop Until hWndDispenseBtn <> 0
    
        Do
            DoEvents
            PostMessage hWndDispenseBtn, BM_CLICK, 0, ByVal 0&
        Loop Until IsWindow(hWndDispenseWindow) = 0
    
    End Sub
    Last edited by koushi; Jan 14th, 2013 at 05:32 PM. Reason: Inserting Code snippet

Tags for this Thread

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