Prevent Failure Notification

Upon request, I need to opt out of the content on the web page. To implement this, I created a Windows application and added a web browser control to the main form. So that I can view the recycling process. I can enter the web page and go to the desired web page. I can also double-click the grid cell programmatically. But the problem is that I get a warning message when I double-click on a grid cell programmatically, and if the required data is not available enter image description here

Thus, the self-service process is interrupted, and we need to manually click the "OK" button to continue the cleaning process. How can I avoid warning messages on failure? Any help would be noticeable. Thanks

+4
source share
1 answer

To programmatically click a warning window, we can use the Windows API FindWindow, FindWindowEx and SendMessage, the idea is to display a warning window, the form in which the WebBrowser control is placed will lose its concentration, at this time we can use FindWindow to get a window window handle warning, finally, we could send a click message to the "OK" button to click it.

[DllImport("user32.dll", SetLastError = true)] static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow); [DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)] private static extern IntPtr FindWindow(string lpClassName, string lpWindowName); [DllImport("user32.dll", CharSet = CharSet.Auto)] static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam); private void Form1_Deactivate(object sender, EventArgs e) { IntPtr hwnd = FindWindow(null, "Message from webpage"); hwnd = FindWindowEx(hwnd, IntPtr.Zero, "Button", "OK"); uint message = 0xf5; SendMessage(hwnd, message, IntPtr.Zero, IntPtr.Zero); } 
+5
source

Source: https://habr.com/ru/post/1483513/


All Articles