Winforms Control Stealing WndProc WM_NCHITEST

牧云@^-^@ 提交于 2019-12-23 02:38:06

问题


I am building a form in C# that uses the WM_NCHITEST event in the WndProc function. It works perfectly with no controls on the page, but when I added a panel to the page my WndProc function stopped receiving WM_NCHITEST events. Any idea what I can do to stop this?

UPDATE: My window in normally borderless, but when I do run it in bordered mode the WM_NCHITTEST event is called when the cursor mouses over the window frame, leaving me to think that the form size control I have (Chromium Embedded Web Browser) is intercepting the messages. Any way to wrest WndProc control back from a unrully window?

protected override void WndProc(ref Message m)
{
    if (m.Msg == 0x0083) //WM_NCAlSIZE
    {
        if (borderless)
        {
            return; //Works even with a control on the page.
        }
    }
    if (m.Msg == 0x0084) //WM_NCHITEST
    {
        Debug.Print("If there is a control on the page I won't print :(");
    }
    base.WndProc(ref m);
}

回答1:


There are 2 complications running Chromium Embedded Web Browser firstly it creates its own window and attaches as a child to yours which means you need to intercept the WndProc of the child window. Secondly CefSharp runs with multi_threaded_message_loop=true which actually fires up a new thread to process messages for the browser which means you need to be a little careful going back and forth from your UI thread and its one.

The solution involves liberal use of PInvoke so I have made a gist for it.

Method to watch a child window messages specifically for use with CefSharp Chromium Embedded Web Browser



来源:https://stackoverflow.com/questions/20484883/winforms-control-stealing-wndproc-wm-nchitest

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!