0

i ve gone through a link while dong google search to handle the dialog boxes prompts in web browser control..this is the link.
http://www.codeproject.com/KB/dialog/WindowInterceptor.aspx?display=Print
and i ve tried like this,

namespace intercept
{
    [DllImport("User32.dll")]

    public class WindowInterceptor
    {
        IntPtr hook_id = IntPtr.Zero;

        Win32.Functions.HookProc cbf;

        /// <summary>
        /// Delegate to process intercepted window
        /// </summary>
        /// <param name="hwnd"></param>
        public delegate void ProcessWindow(IntPtr hwnd);
        ProcessWindow process_window;

        IntPtr owner_window = IntPtr.Zero;

        /// <summary>
        /// Start dialog box interception for the specified owner window
        /// </summary>
        /// <param name="owner_window">owner window; if IntPtr.Zero,
        /// any windows will be intercepted</param>
        /// <param name="process_window">custom delegate to process intercepted window
        /// </param>
        public WindowInterceptor(IntPtr owner_window, ProcessWindow process_window)
        {
            if (process_window == null)
                throw new Exception("process_window cannot be null!");
            this.process_window = process_window;

            this.owner_window = owner_window;

            cbf = new Win32.Functions.HookProc(dlg_box_hook_proc);
            //notice that win32 callback function must be a global variable within class
            //to avoid disposing it!
            hook_id = Win32.Functions.SetWindowsHookEx(Win32.HookType.WH_CALLWNDPROCRET,
                     cbf, IntPtr.Zero, Win32.Functions.GetCurrentThreadId());
        }

        /// <summary>
        /// Stop intercepting. Should be called to calm unmanaged code correctly
        /// </summary>
        public void Stop()
        {
            if (hook_id != IntPtr.Zero)
                Win32.Functions.UnhookWindowsHookEx(hook_id);
            hook_id = IntPtr.Zero;
        }

        ~WindowInterceptor()
        {
            if (hook_id != IntPtr.Zero)
                Win32.Functions.UnhookWindowsHookEx(hook_id);
        }

        private IntPtr dlg_box_hook_proc(int nCode, IntPtr wParam, IntPtr lParam)
        {
            if (nCode < 0)
                return Win32.Functions.CallNextHookEx(hook_id, nCode, wParam, lParam);

            Win32.CWPRETSTRUCT msg = (Win32.CWPRETSTRUCT)Marshal.PtrToStructure
                (lParam, typeof(Win32.CWPRETSTRUCT));

            //filter out create window events only
            if (msg.message == (uint)Win32.Messages.WM_SHOWWINDOW)
            {
                int h = Win32.Functions.GetWindow(msg.hwnd, Win32.Functions.GW_OWNER);
                //check if owner is that is specified
                if (owner_window == IntPtr.Zero || owner_window == new IntPtr(h))
                {
                    if (process_window != null)
                        process_window(msg.hwnd);
                }
            }

            return Win32.Functions.CallNextHookEx(hook_id, nCode, wParam, lParam);
        }
    }




    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        static void ProcessWindow1(IntPtr hwnd)
        {
            //close window
            Win32.Functions.SendMessage(hwnd, (uint)Win32.Messages.WM_CLOSE, 0, 0);
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            webBrowser1.Navigate("d:\\proj\\vslearn\\test.html");
            //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://google.com");
        }
    }
}

but i got error like this..

"'System.Net.Win32' is inaccessible due to its protection level
The type name 'Functions' does not exist in the type 'System.Net.Win32'"

i dont know how should i proceed to make the win32API works.

need help!

Edited by khan17: n/a

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by __avd
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.