By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,972 Members | 901 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,972 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
Hi

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),
EXCEPT

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
flags.

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
WM_NCHITTEST?

Thanks in advance

Stuart
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
HTTRANSPARENT from WM_NCHITTEST;
break;

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
if ("CONTEXT OF THE HIT TEST" <"CURSOR")
{
// i.e. I'm transparent, don't send mouse
events to me
m.Result =
(IntPtr)HitTestValues.HTTRANSPARENT;
}
else
{OK, process WM_SETCURSOR, just for this one exception}

}
}
break;

default:
break;
}

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.