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 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.
Check out this example of a ListView
. It IS possible to make a Control that respects its original cursor messages.
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.
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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With