troubleshooting Question

Click away popup message boxes using SendMessage()

Avatar of DColin
DColinFlag for Thailand asked on
Visual Basic.NET
6 Comments2 Solutions790 ViewsLast Modified:
Hi Experts,

I am using the attached code to click away message boxes from a webbrowser control on a winform application I am writing. This code works very well with all the message boxes generated like, "Confirm order" Yes/No, "Unable to load shopping cart" Abort/Retry/Cancel, etc. but one message box does not respond to attempts to click it away. This message box is the "Internet Explorer Script Error" message box (see attached image).

When this message box pops the TextBoxHandlePopUp control on my winform correctly displays the message boxes winHandle but the TextBoxHandleButton control displays a '0' (zero) as the winHandle for the Message boxes button. When the code succeeds in clicking a message box button the button's winHandle is always correctly displayed by the TextBoxHandleButton. Does this '0' give a clue to what is going wrong with the codes attempt to access the 'Internet Explorer Script Error' message boxes buttons?
Private Sub ClickPopUp()

        Const BM_CLICK As Integer = &HF5
        Dim hwndDialog As Long
        Dim hwndButton As Long
        Dim retval As Long

        hwndDialog = FindWindow(Nothing, "Internet Explorer Script Error")

        TextBoxHandlePopUp.Text = hwndDialog.ToString

        If hwndDialog > 0 Then

            hwndButton = FindWindowEx(hwndDialog, 0, vbNullString, "&No")
            TextBoxHandleButton.Text = hwndButton.ToString

            retval = SetActiveWindow(hwndDialog)
            retval = SendMessage(hwndButton, BM_CLICK, CLng(0), CLng(0))
            retval = SendMessage(hwndButton, BM_CLICK, CLng(0), CLng(0))

        End If

    End Sub
ScriptError.jpg
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 2 Answers and 6 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros