在CMainFrame類中重寫虛方法PreTranslateMessage處理鼠標雙擊事件,方法原型如下:
virtual BOOL PreTranslateMessage(MSG* pMsg);
判斷鼠標雙擊的區域是否爲多文檔選項卡區域,如果是調用全屏代碼使文檔全屏顯示。
判斷鼠標雙擊區域關鍵代碼如下:
BOOL CMainFrame::PreTranslateMessage(MSG* pMsg)
{
switch(pMsg->message)
{
case WM_LBUTTONDBLCLK:
{
CRect rect,b;
GetMDITabs().GetWindowRect(&rect);
POINT pt = pMsg->pt;
BOOL isAction = FALSE;
if(theApp.m_Options.m_bTabsOnTop)
{
if(pt.x > rect.left && pt.x < rect.right
&& pt.y > rect.top && pt.y < rect.top + 20)
{
isAction = TRUE;
}
}
else
{
if(pt.x > rect.left && pt.x < rect.right
&& pt.y > rect.bottom - 20 && pt.y < rect.bottom)
{
isAction = TRUE;
}
}
if(isAction)
{
//處理雙擊事件使用文檔全屏顯示
OnMaxshowtab();
return TRUE;
}
}
break;
}
return CMDIFrameWnd::PreTranslateMessage(pMsg);
}