Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I let .NET wrapper for Rebar decide the mouse cursor?

I'm making a Rebar wrapper for .NET. Here's how I've made my control.

public class Rebar : Control {

    public Rebar() : base() {
        //Control won't even work if I let UserPaint enabled
        SetStyle(ControlStyles.UserPaint, false);
    }

    protected override CreateParams CreateParams {
        get {
            CreateParams cp = base.CreateParams;
            cp.ClassName = "ReBarWindow32"; //REBARCLASSNAME
            cp.ExStyle |= 0x00000080; //WS_EX_TOOLWINDOW
            //Windows Forms will control the position and size, not the native control
            cp.Style |= 0x00000004 | 0x00000008; //CCS_NORESIZE and CCS_NOPARENTALIGN
            return cp;
        }
    }

}

I tested my control by adding a REBARBANDINFO into the control and IT WORKED.

REBARBANDINFO info = new REBARBANDINFO();
info.cbSize = Marshal.SizeOf(typeof(REBARBANDINFO));
info.fMask = RBBIM_TEXT; // 0x00000004
info.lpText = "example";
SendMessage(this.Handle, RB_INSERTBANDW, -1, ref myband);

I won't include the implementation of my p/invoke signatures because everything is fine there.

The problem starts here

The control doesn't work the way I've expected, the Rebar cursor isn't respected and Cursor property takes control over the cursor, it even overrides the resize cursor.

Expectation

Expectation of Rebar wrapper

Reality

Reality of Rebar wrapper

Is that even possible? Yes, it is

Check out this example of a ListView. It IS possible to make a Control that respects its original cursor messages.

ListView example

How can I make my Rebar decide the mouse cursor instead of Cursor property?

Aditional: I've done my best to ask a good question. I double-checked the question to ensure it can be understood.

like image 516
CodigosTutoriales Avatar asked Feb 12 '18 22:02

CodigosTutoriales


1 Answers

Control class handles WM_SETCURSOR and has its own logic.

As an option you can override WndProc and let the DefWndProc handle WM_SETCURSOR:

const int WM_SETCURSOR = 0x0020;
protected override void WndProc(ref Message m)
{
    if (m.Msg == WM_SETCURSOR)
        base.DefWndProc(ref m);
    else
        base.WndProc(ref m);
}
like image 76
Reza Aghaei Avatar answered Sep 23 '22 15:09

Reza Aghaei