拦截窗体消息—使用NativeWindow

NativeWindow提供窗口句柄和窗口过程的低级封装。下面是拦截ContextMenu的显示和消失的例子

    public class NativeContextMenu : NativeWindow
    {

        private const int WM_EXITMENULOOP = 0x212;
        private const int WM_ENTERMENULOOP = 0x0211;

        public event System.EventHandler ExitMenuLoop;
        private IntPtr handle;

        public NativeContextMenu(IntPtr handle)//使用窗体句柄
        {
            this.handle = handle;
            this.AssignHandle(handle);
        }

        protected override void WndProc(ref Message m)
        {
            switch (m.Msg)
            {
                case WM_EXITMENULOOP:
                    if (ExitMenuLoop!=null)
                    {
                        ExitMenuLoop(this, new EventArgs());
                    }
                    break;
            }
            base.WndProc(ref m);
        }
    }

 

在CF中没有NativeWindow,使用using OpenNETCF.Windows.Forms;

阅读更多
文章标签: class null
想对作者说点什么? 我来说一句

关于QT nativeWindow

nativewindow

u011352234 u011352234

2016-12-23 13:53:28

阅读数:1734

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭