3

I want to be able to switch between immediate and smart docking in a MFC client application. By default DT_IMMEDIATE will be set so the dock panes will function similar to Visio. However when the user presses and holds down the Ctrl key I want to switch to DT_SMART and display the smart markers as they drag or move dock panes around so they can see the various places where they can dock similar to Visual Studio.

I tried applying this with a key down handler but it does not fire. I then resorted to using PreTranslateMessage and although it catches the input and sets the docking mode successfully it does not display or enable the smart docking as expected.

BOOL CMainFrame::PreTranslateMessage(MSG *pMsg)
{
    // everything fires and gets set correctly when holding down or pressing Ctrl
    // it doesn't ever turn smart docking back on or doesn't display smart markers
    // does mouse input interrupt so it doesn't take effect?
    if (pMsg->message == WM_KEYDOWN)
    {
            // also checks that repeating bit is not set in lParam
        if (pMsg->wParam == VK_CONTROL && ((pMsg->lParam & (1 << 30)) == 0))
        {
            CDockingManager::SetDockingMode(DT_SMART);
            LOG_DEBUG("DT_SMART");
            return TRUE;
        }
    }
    else if (pMsg->message == WM_KEYUP)
    {
        if (pMsg->wParam == VK_CONTROL)
        {
            CDockingManager::SetDockingMode(DT_IMMEDIATE);
            LOG_DEBUG("DT_IMMEDIATE");
            return TRUE;
        }
    }

    return CMDIFrameWndEx::PreTranslateMessage(pMsg);
}

In the log file I can see that it alternates between setting DT_SMART and DT_IMMEDIATE when pressing and releasing Ctrl key however only immediate docking is working as expected. Is there some redrawing or some other calls I need to make to get this to work?

AJG85
  • 15,849
  • 13
  • 42
  • 50

2 Answers2

1

Just to be sure: Did you hold the key down for some time? When you press and release the key it will fire twice(down and up) resulting in the mode being reset to DT_IMMEDIATE (when you release the key). Alternatively I would propose to let the mode being switched between DT_IMMEDIATE and DT_SMART when only when the key is pressed down.

  • Yes various testing but nothing that works yet, that's actually where the check for the repeat bit came from as originally holding down ctrl was setting DT_SMART multiple times. I'm partially curious if this is even a plausible change without removing then re-adding dock panes to the manager. – AJG85 Jun 16 '11 at 15:36
  • Explicitly calling `RedrawWindow()` didn't make a difference and that's preferably avoidable anyway. – AJG85 Jun 17 '11 at 18:39
0

I know this topic is old. But... I've noticed that calling

CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerVS2005));
CDockingManager::SetDockingMode(DT_SMART);

Seems to fix the missing bitmaps, at least for the current Windows session. Even if you later use a different VisualManager. As to why it's doing that is still a total mystery...

[Edit] This line in CMFCVisualManagerVS2005 constructor seems to do the trick.

CDockingManager::EnableDockSiteMenu();
Michaël Roy
  • 6,338
  • 1
  • 15
  • 19