By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,386 Members | 1,861 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,386 IT Pros & Developers. It's quick & easy.

Windows Forms - Is there a way to determine the "context" in which WM_NCHITTEST Message is being used?

P: n/a

I have a user control which the user can "drag" across the screen (I'm
not using "real" .NET drag drop - instead a single click flavour,
where the control is drawn at the mouse position).

Depending on whether the user has "picked up" the control or not, I
need the following behaviour

1) When the control is being dragged, the control must not intercept
any mouse events (i.e. so user can drop the control / other forms and
controls "underneath the control can intercept the MOUSE messages),

2) However, even when being dragged, I still need control over the
mouse cursor from the control

Rather than manually re-raising events for all the mouse messages on
the control, returning WM_NCHITTEST as HTTRANSPARENT when being
dragged does the trick for part 1)
However, unfortunately, I no longer have any control over the mouse
cursor - my control no longer receives WM_SETCURSOR when being
dragged, as it would seem that since the control's "HITTEST" is
HTTRANSPARENT, that the WM_CURSOR's are being passed underneath as
well (kind of obvious I guess :-)

Does anyone know if I can be more 'selective' about the HITTESTing.
Unfortunately, it seems LPARAM contains only the coords, and no other

Otherwise I guess I will need to trap and re-raise all Mouse Events to
achieve the above
(I guess I could also set the cursor on the 'underneath' controls /
forms, but this isn't ideal / encapsulated)

* Alternatively, can I force a WM_CURSOR message from the

Thanks in advance

protected override void WndProc(ref Message m)
Boolean bDoBase;
bDoBase = true;

switch (m.Msg)
case WindowsMessages.WM_SETCURSOR:
Cursor.Current = // One of our custom cursors,
this works fine, but doesn't get called once we have returned

case WindowsMessages.WM_NCHITTEST:
// If user is dragging, we don't want this control to intercept
mouse clicks etc, however we DO still want to process the WM_CURSOR
messages so we can control which cursor to use
if (m_bDragging)
bDoBase = false;
// Pseudo Code
// i.e. I'm transparent, don't send mouse
events to me
m.Result =
{OK, process WM_SETCURSOR, just for this one exception}



if (bDoBase)
base.WndProc(ref m);

Apr 10 '07 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.