⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 program.cs

📁 Introduction Sometimes you may collide with the following problem: a third-party binary component o
💻 CS
字号:
using System;
using System.Collections;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Threading;

namespace CliverSoft
{
    static class Program
    {
        [STAThread]
        static void Main(string[] args)
        {

            //form with WebBrowser
            Form1 form = new Form1();
            //Start intercepting all dialog boxes owned by form
            WindowInterceptor d = new WindowInterceptor(form.Handle, ProcessWindow1);
            form.Show();
            form.Navigate("http://localhost/test1.htm");
                        
            Application.Run();

            //Stop intercepting. Should be called to calm unmanaged code correctly
            d.Stop();
        }
        
        //we need to have a form that will be an owner for our own message boxes 
        //to save them from intercepting
        static Form2 f = new Form2();
        

        /// <summary>
        ///closing message box
        /// </summary>
        /// <param name="hwnd"></param>
        static void ProcessWindow1(IntPtr hwnd)
        {
            //getting window caption
            StringBuilder text = new StringBuilder(255);
            Win32.Functions.GetWindowText(hwnd, text, 255);
            if (MessageBox.Show(f, "FOUND:" + text + "\nClose it?", "WindowInterceptor", MessageBoxButtons.YesNo) != DialogResult.Yes)
                return;                

            //close window
            Win32.Functions.SendMessage(hwnd, (uint)Win32.Messages.WM_CLOSE, 0, 0);
        }
        
        /// <summary>
        ///clicking OK on confirm message box
        /// </summary>
        /// <param name="hwnd"></param>
        static void ProcessWindow2(IntPtr hwnd)
        {
            //looking for button "OK" within the intercepted window
            IntPtr h = (IntPtr)Win32.Functions.FindWindowEx(hwnd, IntPtr.Zero, "Button", "OK");
            if (h != IntPtr.Zero)
            {
                //clicking the found button
                Win32.Functions.SendMessage((IntPtr)h, (uint)Win32.Messages.WM_LBUTTONDOWN, 0, 0);
                Win32.Functions.SendMessage((IntPtr)h, (uint)Win32.Messages.WM_LBUTTONUP, 0, 0);
            }
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -