No subclassing needed (phew). Managed to get it working by hijacking the PreTranslateMessage of the mainframe. If the current message is a middle-mouse-button message, I check the location of the click. If it was on a tab then I close that tab.
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);
}
demoncodemonkey
2009-08-06 13:20:23