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?