How to tell if the mouse is down in RibbonWindow caption area

Ribbon for WPF Forum

Posted 7 years ago by Vincent Chen
Version: 12.1.0561
Avatar

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.

Comments (2)

Answer - Posted 7 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Vincent,

Sorry but since our RibbonWindow's chrome is rendered by us, we're not supporting all the API messages.  We just watch OnMouseDown in the RibbonWindow and call its DragMove method if we detect the mouse is over a value title area.  If you look at how Microsoft implemented DragMove, it seems like a WM_SYSCOMMAND message is sent.  Perhaps you can watch that instead?


Actipro Software Support

Posted 7 years ago by Vincent Chen
Avatar

Thanks for the suggestion. It works better than tracking WM_NCLBUTTONDOWN.

The latest build of this product (v2019.1 build 0683) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.