DColin
asked on
Click away popup message boxes using SendMessage()
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?
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
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.
ASKER
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?
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?
ASKER
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).
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).
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.