dem*_*key 6 mfc tabbed-document-interface mfc-feature-pack
如果创建新的 MFC 应用程序(带有 MFC 功能包)并使用所有默认值,请单击“完成”。它使用新的“选项卡式文档”样式创建 MDI 应用程序。
我认为这些都很棒,但令我烦恼的是我无法通过中键单击选项卡来关闭选项卡式文档窗口。
这在 Firefox、IE、Chrome 以及更重要的VS2008中都是可能的。但是单击选项卡上的中间按钮不会执行任何操作。
我不知道如何覆盖选项卡栏以允许我处理消息ON_WM_MBUTTONDOWN
。有任何想法吗?
编辑:猜测我需要对从 CMDIFrameWndEx::GetMDITabs 返回的 CMFCTabCtrl 进行子类化...
不需要子类化(唷)。通过劫持主机的 PreTranslateMessage 使其正常工作。如果当前消息是鼠标中键消息,我会检查单击的位置。如果它在选项卡上,那么我会关闭该选项卡。
BOOL CMainFrame::PreTranslateMessage(MSG* pMsg)
{
switch (pMsg->message)
{
case WM_MBUTTONDBLCLK:
case WM_MBUTTONDOWN:
{
//clicked middle button somewhere in the mainframe.
//was it on a tab group of the MDI tab area?
CWnd* pWnd = FromHandle(pMsg->hwnd);
CMFCTabCtrl* tabGroup = dynamic_cast<CMFCTabCtrl*>(pWnd);
if (tabGroup)
{
//clicked middle button on a tab group.
//was it on a tab?
CPoint clickLocation = pMsg->pt;
tabGroup->ScreenToClient(&clickLocation);
int tabIndex = tabGroup->GetTabFromPoint(clickLocation);
if (tabIndex != -1)
{
//clicked middle button on a tab.
//send a WM_CLOSE message to it
CWnd* pTab = tabGroup->GetTabWnd(tabIndex);
if (pTab)
{
pTab->SendMessage(WM_CLOSE, 0, 0);
}
}
}
break;
}
default:
{
break;
}
}
return CMDIFrameWndEx::PreTranslateMessage(pMsg);
}
Run Code Online (Sandbox Code Playgroud)