protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case PI.WM_NCLBUTTONDOWN:
{
// Perform a hit test to determine which area the mouse press is over at the moment
uint result = PI.SendMessage(this.Handle, (int)PI.WM_NCHITTEST, 0, (uint)m.LParam);
// Only want to override the behaviour of moving the window via the caption bar
if (result == PI.HITTEST_CAPTION)
{
// Extract screen position of the mouse from the message LPARAM
Point screenPos = new Point((short)((uint)m.LParam & 0x0000FFFFU),
(short)(uint)(((uint)m.LParam & 0xFFFF0000U) >> 16));
// Find the mouse offset relative to the top left of the window
Point offset = new Point(screenPos.X - Location.X, screenPos.Y - Location.Y);
// Do not intercept message if inside the max/close buttons
if (!HitTestMaxButton(offset) && !HitTestCloseButton(offset))
{
// Capture the mouse until the mouse us is received and gain focus so we look active
Capture = true;
Activate();
// Use event to notify the request to drag the window
OnWindowCaptionDragging(new ScreenAndOffsetEventArgs(screenPos, offset));
// Eat the message!
return;
}
}
}
break;
case PI.WM_KEYDOWN:
base.WndProc(ref m);
if (_floatingMessages != null)
_floatingMessages.OnKEYDOWN(ref m);
return;
case PI.WM_MOUSEMOVE:
base.WndProc(ref m);
if (_floatingMessages != null)
_floatingMessages.OnMOUSEMOVE();
return;
case PI.WM_LBUTTONUP:
base.WndProc(ref m);
if (_floatingMessages != null)
_floatingMessages.OnLBUTTONUP();
return;
}
base.WndProc(ref m);
}