通过处理 NC_HITTEST 移动控件时设置 SizeAll 光标

2024-04-12

我写了WndProc可移动控件的方法如下:

 protected override void WndProc(ref Message m)
    {
        const int WM_NCHITTEST = 0x0084;


        if (m.Msg == WM_NCHITTEST)
        {

            base.WndProc(ref m);
            if ((int)m.Result == 0x1)
                m.Result = (IntPtr)0x2;

            return;
        }

            base.WndProc(ref m);


    }

并设置SizeAll光标为光标属性。但是当我们像我一样设置 m.Result 时,光标将是Default任何状况之下。我能怎么做?


你应该处理WM_SETCURSOR too.

您可能还想处理WM_NCLBUTTONDBLCLK防止双击时控件最大化:

protected override void WndProc(ref Message m)
{
    const int WM_NCHITTEST = 0x84;
    const int WM_SETCURSOR = 0x20;
    const int WM_NCLBUTTONDBLCLK = 0xA3;
    const int HTCAPTION = 0x2;
    if (m.Msg == WM_NCHITTEST)
    {
        base.WndProc(ref m);
        m.Result = (IntPtr)HTCAPTION;
        return;
    }
    if (m.Msg == WM_SETCURSOR)
    {
        if ((m.LParam.ToInt32() & 0xffff) == HTCAPTION)
        {
            Cursor.Current = Cursors.SizeAll;
            m.Result = (IntPtr)1;
            return;
        }
    }
    if ((m.Msg == WM_NCLBUTTONDBLCLK))
    {
        m.Result = (IntPtr)1;
        return;
    }
    base.WndProc(ref m);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

通过处理 NC_HITTEST 移动控件时设置 SizeAll 光标 的相关文章

随机推荐