Set SizeAll cursor while moving control by handling NC_HITTEST
Asked Answered
C

1

3

I wrote the WndProc method for a moveable control such this:

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


    }

and setted SizeAll cursor for the cursor property. but when we set m.Result as i did, the cursor will be Default in any case. How can i do?

Coleen answered 2/11, 2015 at 15:43 Comment(6)
What is it you're trying to accomplish?Mercator
See C#: How to drag a from by the form and it's controls?Cowan
@roryap : i mean with this way , the cursor of control will be 'Default' in any caseColeen
@hosseinsafavi -- I'm sorry, I don't understand you.Mercator
@Cowan thank you my friend. it working :)Coleen
You should handle WM_SETCURSOR too. Also you should hanlde WM_NCLBUTTONDBLCLK to prevent your control from being maximized when you double click on it:Shahaptian
S
4

You should handle WM_SETCURSOR too.

Also you may want to hanlde WM_NCLBUTTONDBLCLK to prevent your control from being maximized when you double click on it:

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);
}
Shahaptian answered 2/11, 2015 at 16:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.