We have some code that deals with window movements that requires a prepartion step. This step is triggered by handling the WM_NCLBUTTONDOWN message. If the hit test result is HTCAPTION, we do the preparation step and get ready for the window to move. This works with the standard WPF Window class. When we switched to use RibbonWindow with a Ribbon, we no longer receive WM_NCLBUTTONDOWN when the mouse is down in the caption area. Instead, we get WM_LBUTTONDOWN. Is there anyway that we can tell if the mouse is down in the caption area, or whether the window is about to start moving?
Here are some code snippets. OS is Win7. We install an HwndSourceHook in the SourceInitialized handler, this is a RibbonWindow
private void OnSourceInitialized(object sender, EventArgs e)
{
var hWnd = new WindowInteropHelper(this).Handle;
var source = HwndSource.FromHwnd(hWnd);
source.AddHook(WndProc);
}
In our hook, WndProc, we do the following:
private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
switch ((WM)msg)
{
case WM.NCLBUTTONDOWN:
if ((int)HT.CAPTION == wParam.ToInt32())
{
// We use this distinguish between window moving and resizing.
m_PrimedForMove = true
}
break;
case WM.ENTERSIZEMOVE:
if (m_PrimedForMove)
{
WindowMovingStart();
}
break;
// other cases
}
// etc...
}
Clicking on the window's border still triggers WM_NCLBUTTONDOWN messages. I can write some code that set m_PrimedForMove to false if the hit test result is HTTOP or HTBOTTOM, etc. as a work around. But I would like to know if there are any other ways to solve it.