Question click button on window via sendmessage doesn`t work

peterg2000

New member
Joined
Aug 21, 2019
Messages
4
Programming Experience
10+
I access a web page via code and try to export and download an excel file. But at the usual 'Open Save Cancel' window I can't get the save button to fire!
I found a few similar posts here but the solutions found don't work!

Here is what I have !

Code:
VB.NET:
    Sub ClosePopup(ByVal WindowHandle As IntPtr)

        Dim clsChildHandles As ArrayList = GetChildWindowHandles(WindowHandle)
        Dim teststr As String
        Dim prthandleint As Long
        'look through all of the child handles of the window for an "Save" button (this method
        'can also be used to gather more specific information about the dialog itself, such as
        'the message being displayed)...
        For Each ptrHandle As IntPtr In clsChildHandles
            'if the Save button is found, click it...
            teststr = GetWindowText(ptrHandle)
            prthandleint = ptrHandle ' was having trouble with putting an intptr in debug.print!
            Debug.Print(teststr & " = Child TEXT:   len=" & teststr.Length & "handle = " & prthandleint & vbCrLf)

            If teststr.Contains("&Save") Then
                ClickButton(ptrHandle)  ' THIS PART WORKS AS I GET HERE!
                Exit For
            Else
                Debug.Print(teststr & " = ELSE Child TEXT:   len=" & vbCrLf)
            End If
        Next

    End Sub

    Const BM_CLICK As Long = &HF5&
    Public Const WM_LBUTTONDOWN As UInteger = &H201
    Public Const WM_LBUTTONUP As UInteger = &H202
    Public Const WM_COMMAND As Integer = &H111       


    Sub ClickButton(ByVal WindowHandle As IntPtr)

        SendMessage(xAsIntPtr, BM_CLICK, &H83, WindowHandle) ' Sendmessage has no effect on File download window!

        'I left in several flavors of the sendmessage that I've tried!
        'SendMessageW(WindowHandle, WM_ACTIVATE, New IntPtr(WA_ACTIVE), IntPtr.Zero)
        'SendMessageW(WindowHandle, BM_CLICK, IntPtr.Zero, IntPtr.Zero)
        'SendMessage(WindowHandle, WM_LBUTTONDOWN, 0&, MakeLParam(180, 220))
        'SendMessage(WindowHandle, WM_LBUTTONUP, 0&, MakeLParam(180, 220))
      
    End Sub


I've matched the handles with what I see using Spy++ . But I was wondering if I should see any activity on the save button with Spy++
from the code activity like I do when I actually click on the button with a mouse?

Appreciate any help in advance!

Pete
 
Last edited by a moderator:

Latest posts

Back
Top