Winforms控件窃取WndProc WM_NCHITEST [英] Winforms Control Stealing WndProc WM_NCHITEST

查看:236
本文介绍了Winforms控件窃取WndProc WM_NCHITEST的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在C#中构建一个表单,该表单在WndProc函数中使用WM_NCHITEST事件.它在页面上没有任何控件的情况下完美运行,但是当我在页面上添加面板时,我的WndProc函数停止接收WM_NCHITEST事件.知道我能做些什么来阻止这种情况吗?

更新:我的窗口通常是无边界的,但是当我以有边界的方式运行它时,当光标悬停在窗口框架上时,会调用WM_NCHITTEST事件,这让我认为该窗体我拥有的大小控制(Chromium嵌入式Web浏览器)正在拦截消息.有什么方法可以从不受干扰的窗口中夺回WndProc控件?

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);
}

解决方案

运行Chromium嵌入式Web浏览器有2个复杂问题,首先,它会创建自己的窗口并将其作为子级附加到您的窗口中,这意味着您需要拦截该子级的WndProc窗户.其次,CefSharp与multi_threaded_message_loop=true一起运行,它实际上触发了一个新线程来处理浏览器的消息,这意味着您需要谨慎地从UI线程及其一个线程来回移动.

该解决方案涉及自由使用PInvoke,所以我为此做了要点.

观看专门用于CefSharp Chromium嵌入式Web浏览器的子窗口消息的方法

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);
}

解决方案

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

这篇关于Winforms控件窃取WndProc WM_NCHITEST的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆