2

I coded this junk:

using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    class SmartWebBrowser : WebBrowser
    {
        private const int WM_LBUTTONDOWN = 0x0201;
        private const int WM_LBUTTONUP = 0x0202;
        private const int WM_LBUTTONDBLCLK = 0x0203;

        private const int WM_RBUTTONDOWN = 0x0204;
        private const int WM_RBUTTONUP = 0x0205;
        private const int WM_RBUTTONDBLCLK = 0x0206;

        private const int WM_MBUTTONUP = 0x0208;
        private const int WM_MBUTTONDOWN = 0x0209;

        public override bool PreProcessMessage(ref Message msg)
        {
            bool allow_propagation = true;

            switch (msg.Msg)
            {
                case WM_LBUTTONDOWN:
                case WM_LBUTTONUP:
                case WM_LBUTTONDBLCLK:
                case WM_RBUTTONDOWN:
                case WM_RBUTTONUP:
                case WM_RBUTTONDBLCLK:
                case WM_MBUTTONUP:
                case WM_MBUTTONDOWN:
                    allow_propagation = false; //breakpoint here
                    break;
            }

            if (allow_propagation)
                return base.PreProcessMessage(ref msg);
            else
                return false;
        }

        protected override void WndProc(ref Message msg)
        {
            bool allow_propagation = true;

            switch (msg.Msg)
            {
                case WM_LBUTTONDOWN:
                case WM_LBUTTONUP:
                case WM_LBUTTONDBLCLK:
                case WM_RBUTTONDOWN:
                case WM_RBUTTONUP:
                case WM_RBUTTONDBLCLK:
                case WM_MBUTTONUP:
                case WM_MBUTTONDOWN:
                    allow_propagation = false; //breakpoint here
                    break;
            }

            if (allow_propagation)
                base.WndProc(ref msg);
        }
    }
}

But breakpoints never trigger. What I doing wrong? Overriding WndProc for such things is common practice, but no work here.

I trying to stop clicks propagation to document, so user can scroll it, but can't interact with it via clicks.

Kosmo零
  • 4,001
  • 9
  • 45
  • 88
  • 1
    It is not that simple, your WndProc() override is not the first one that gets the messages. They get hijacked and passed to the document before you can see them. Important, that keeps the Javascript in the html page functional. You'd need a custom WebBrowserSite that overrides ISimpleFrameSite.PreMessageFilter(). I've heard of it being done, you got google keywords to search for. – Hans Passant Jul 20 '15 at 16:17
  • @HansPassant - Thank you. Is is already answer on "Why", so make it as answer. – Kosmo零 Jul 20 '15 at 16:22
  • I don't want to support an answer like that for the rest of my natural life. Post the actual solution you found and accept it as the answer to the question. – Hans Passant Jul 20 '15 at 16:23
  • [`WM_MBUTTONDOWN` is `0x0207`](https://msdn.microsoft.com/en-us/library/windows/desktop/ms645610%28v=vs.85%29.aspx) – stuartd Jul 20 '15 at 16:24
  • @HansPassant - for now I found nothing aside of this http://referencesource.microsoft.com/System.Windows.Forms/winforms/Managed/System/WinForms/WebBrowserSiteBase.cs.html#System.Windows.Forms/winforms/Managed/System/WinForms/WebBrowserSiteBase.cs and I trying to understand if this is what I need. – Kosmo零 Jul 20 '15 at 16:35
  • @stuartd - Thank you. You are attentive. – Kosmo零 Jul 20 '15 at 16:37

0 Answers0