Clicking a button in a different program

garriew

Member
Joined
Sep 13, 2013
Messages
13
Programming Experience
Beginner
I have a program that uses the IE engine at when it (IE) gives the alert prompt;

"Your current security settings do not allow this file to be downloaded"

the program using IE crashes/freezes if it's not clicked within a few seconds. So, I want to write a program that runs in the background looking/waiting for it when.

Back in the VB 3.0 days I knew, more less, how to do this but now a decade later it has slipped my mind. I'm pretty sure I would use API and I use to have a program to tell me a Windows name but again, time has caused it to slip away.

Any suggestions?

MTIA
-g
 
Button not being clicked

The code below is suppose to find a "Security alert" window and click the OK button when I am using a program that is basically a custom browser using IE.

While it does find the window, it doesn't click the OK button. It thinks it does but really doesn't. However, if I use IE normally it clicks the button.

Example of an alert is when you click download at:
Download Microsoft Application Compatibility Toolkit 5.6 from Official Microsoft Download Center

NOTE: I get the alert because I only allow downloads from Trusted sites in IE.

Any help would be much appreciated.

Oh yeah. I tried to edit my other post but couldn't find the edit link...

VB.NET:
 Private Const BM_CLICK = &HF5
    Private Declare Auto Function FindWindow Lib "user32.dll" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
    Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hWnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As IntPtr) As IntPtr
    Private Declare Auto Function FindWindowEx Lib "user32.dll" (ByVal hwndParent As IntPtr, ByVal hwndChildAfter As IntPtr, ByVal lpszClass As String, ByVal lpszWindow As String) As IntPtr

 
 Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
        Dim hWndMsgBox As Long, hWndButton As Long
        hWndMsgBox = FindWindow("#32770", "Security Alert")
        If hWndMsgBox Then
            'AppActivate("Security Alert")
            hWndMsgBox = FindWindow("#32770", "Security Alert")
            If hWndMsgBox Then hWndButton = FindWindowEx(hWndMsgBox, 0&, "Button", "OK")
            If hWndButton Then SendMessage(hWndButton, BM_CLICK, 0&, 0&)
            Label4.Text = Label4.Text + 1
        End If
    End Sub
 
Back
Top