?
Solved

Click away popup message boxes using SendMessage()

Posted on 2009-12-22
6
Medium Priority
?
758 Views
Last Modified: 2012-05-08
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

Open in new window

ScriptError.jpg
0
Comment
Question by:DColin
  • 4
  • 2
6 Comments
 
LVL 4

Expert Comment

by:me655321
ID: 26109737
The 0 means it's not finding the dialog window. I notice your variables look like vb6 declarations instead of VB.Net. They should be integers or IntPtr instead of Long...

        Dim hwndDialog As IntPtr
        Dim hwndButton As IntPtr
        Dim retval As IntPtr

I don't think that will fix your problem though. Seems like when you're running that code, it's not finding a window.
0
 
LVL 4

Expert Comment

by:me655321
ID: 26109754
By the way, you should be able to set the property ScriptErrorsSupressed on your WebBrowser control to true and those error boxes won't show at all.
0
 

Author Comment

by:DColin
ID: 26110275
Hi me655321:

By the way, you should be able to set the property ScriptErrorsSupressed on your WebBrowser control to true and those error boxes won't show at all.

How would I go about doing this?

I have done this on my desktop IE8 and I do not get the errors but how do I do this for the webbrowser control?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:DColin
ID: 26110280
Hi me655321:

The 0 means it's not finding the dialog window.

The window is being found and it's handle is being displayed by the TextBoxHandlePopUp control, t it is the button handle that is not being found (TextBoxHandleButton).
0
 
LVL 4

Accepted Solution

by:
me655321 earned 2000 total points
ID: 26111533
>> How would I go about doing this?
If you right click your webbrowser control and select properties, that will focus the property grid where ScriptErrorsSuppressed is one of the options. Change it to True. Or you can write     WebBrowser1.ScriptErrorsSuppressed = True    Somewhere in your code(ie in the form load sub or 'new' sub).
The window is being found and it's handle is being displayed by the TextBoxHandlePopUp control, t it is the button handle that is not being found (TextBoxHandleButton).
Sorry, I misread what you wrote. The button handle is not being found.
0
 
LVL 4

Assisted Solution

by:me655321
me655321 earned 2000 total points
ID: 26111606
By the way, I looked at the script error dialog and there are no children controls to it. Unlike the other dialogs you're "clicking away", the buttons on this one are not separate controls. They are just drawn on the parent form. You could probably tell windows to click the window in the right spot...
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, "", "")
            TextBoxHandleButton.Text = hwndButton.ToString

            retval = SetActiveWindow(hwndDialog)
            ClickWindow(hwndButton, 192, 224)
            ClickWindow(hwndButton, 192, 224)

        End If

    End Sub
    Public Sub ClickWindow(ByVal hwnd As Integer, ByVal X As Integer, ByVal Y As Integer)
        Dim lparam As Integer = (X And &HFFFF&) Or (Y * &H10000)
        Call PostMessage(hwnd, &H201, 0, lparam)
        Call PostMessage(hwnd, &H202, 0, lparam)
    End Sub

Open in new window

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question