Reputation: 452
I have a C# program that I've been running in windows 7 fine but now that I upgraded to windows 10 with a newer browser, it has stopped working correctly.
The issue is with handling of dialog boxes. When it pops up, I just want to close the box. I used the below code. If it pops up again, the code executes again to close it.
IntPtr hwnd = FindWindow("#32770", "Message from webpage");
if (hwnd != IntPtr.Zero)
{
hwnd = FindWindowEx(hwnd, IntPtr.Zero, "Button", "OK");
SendMessage(hwnd, 0xf5, IntPtr.Zero, IntPtr.Zero);
Now, when more than one box pops up, there will be a checkbox that says "Don’t let this page create more messages". The above code is unable to close this box. I'm not sure what I am missing.
I'm not even sure why this error pops up in the first place. If I intervene and manually click the button on the webpage, I don't get the popup usually. But that is another issue.
Upvotes: 0
Views: 784
Reputation: 570
Try just send WM_CLOSE
message to the window instead of emulating click on the OK button:
IntPtr hwnd = FindWindow("#32770", "Message from webpage");
if (hwnd != IntPtr.Zero)
{
SendMessage(hwnd, 0x10, IntPtr.Zero, IntPtr.Zero);
}
Upvotes: 1