zoukankan      html  css  js  c++  java
  • c# Wndproc的使用方法

     

    protected override void WndProc(ref Message m)
    {
    const int WM_SYSCOMMAND = 0x0112;
    const int SC_CLOSE = 0xF060;
    if (m.Msg == WM_SYSCOMMAND && (int) m.WParam == SC_CLOSE)
    {
    // 屏蔽传入的消息事件
    this.WindowState = FormWindowState.Minimized;
    return;
    }
    base.WndProc(ref m);
    }

    protected override void WndProc(ref Message m)
    {
    const int WM_SYSCOMMAND = 0x0112;
    const int SC_CLOSE = 0xF060;
    const int SC_MINIMIZE = 0xF020;
    if (m.Msg == WM_SYSCOMMAND && ((int)m.WParam == SC_MINIMIZE || (int)m.WParam == SC_CLOSE))
    {
    //最小化到系统栏
    this.Hide();
    return;
    }
    base.WndProc(ref m);
    }

    重写 WndProc函数来同时实现无标题栏的窗体移动和禁止双击窗体最大化

    protected override void WndProc(ref Message m)
    {
    const int WM_NCHITTEST = 0x84;
    const int HTCLIENT = 0x01;
    const int HTCAPTION = 0x02;
    const int WM_SYSCOMMAND = 0x112;
    const int SC_MAXMIZE = 0xF030;
    const int WM_NCLBUTTONDBLCLK = 0xA3;
    switch (m.Msg)
    {
    case 0x4e:
    case 0xd:
    case 0xe:
    case 0x14:
    base.WndProc(ref m);
    break;
    case WM_NCHITTEST://鼠标点任意位置后可以拖动窗体

    this.DefWndProc(ref m);
    if (m.Result.ToInt32() == HTCLIENT)
    {
    m.Result = new IntPtr(HTCAPTION);
    return;
    }
    break;
    case WM_NCLBUTTONDBLCLK://禁止双击最大化
    Console.WriteLine(this.WindowState);
    return;
    break;
    default:
    base.WndProc(ref m);
    break;
    }
    }

    补充一个修改注册表的方法

    可以用在某窗体或者某控件的MouseEnter和MouseLeave事件中
    在HKEY_CURRENT_USER\Control Panel\Desktop的WheelScrollLines的值4改变就行了,0表示禁止滚轮,1表示打开滚轮

  • 相关阅读:
    (转)C#调用默认浏览器打开网页的几种方法
    (链接)打印相关_.NET打印小资料
    (推荐)WPF动画教程
    (转)C# 打印PDF文件使用第三方DLL
    问题解决_(转载)在VisualStudio 2012上使用MVC3出现错误的解决办法
    分布式集群
    关于集群并发问题
    关于分布式事务的处理
    分布式与集群理解之部署结构
    分布式与集群理解
  • 原文地址:https://www.cnblogs.com/xiaogelove/p/2530380.html
Copyright © 2011-2022 走看看