• 拦截信息方法


    但是你可以拦截这个控件的双击消息。 以下代码可加在控件的父窗口(假设为Form1),并在Form1初始化后安装拦截挂钩。同样的方法也可屏蔽那控件的其它消息,如屏蔽它的右键事件。

    private const int GWL_WNDPROC = -4;

    private const int WM_LBUTTONDOWN=0x0201;

    private const int WM_LBUTTONUP=0x0202;

    private const int WM_LBUTTONDBLCLK=0x0203;//双击消息

    [DllImport("user32.dll", CharSet = CharSet.Auto)]

    private static extern IntPtr SetWindowLong(IntPtr hWnd, int nIndex, MyWndProc wndProc);

    [DllImport("user32.dll", CharSet = CharSet.Auto)]

    private static extern IntPtr CallWindowProc(IntPtr wndProc, IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);

     

    public delegate IntPtr MyWndProc(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);

     

    private IntPtr OldWndProc = IntPtr.Zero;

    private MyWndProc Wpr = null;

    private IntPtr MyControlWndProc(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam) {

     switch (msg)

     { case WM_LBUTTONDBLCLK://拦截双击消息

    /*在这里,你想干什么就干什么*/

    ....................... .......................

    return (IntPtr)0;

    default:

     return CallWindowProc(OldWndProc, hWnd, msg, wParam, lParam);

    }

    }

    //假设那个控件变量名为 _thatControl

     

    private void InitializeThatControl()

    { //初始化的时候安装消息拦截

    this.Wpr = new MyWndProc(this.MyControlWndProc);

    this.OldWndProc = SetWindowLong(_thatControl.Handle, GWL_WNDPROC, Wpr);

    }

     

    public Form1()

     {

    InitializeComponent();

    InitializeThatControl();//加这句,在Form初始化后安装消息拦截

    }

  • 相关阅读:
    redis-cluster配置
    centeros7安装docker
    redis-sentinel主从复制高可用
    redis的主从同步
    redis安全(加入密码)
    redis的持久化相关操纵
    maria(mysql)的主从复制
    nginx+uwsgi+virtualenv+supervisor部署项目
    scrapy_redis之官网列子domz
    豆瓣模拟登录(双层html)
  • 原文地址:https://www.cnblogs.com/zjgtlkj/p/3278646.html
Copyright © 2020-2023  润新知