在CMainFrame類中添加下列成員變量和成員函數(使用ClassWizard),下面是這些變量和函數的功能說明:
成員變量:
BOOL m_bFullScreen; //全屏幕顯示標志
CRect m_FullScreenWindowRect; //全屏幕顯示窗口Rect
WINDOWPLACEMENT m_wpPrev; //用於保存正常視圖時的窗口位置信息
CToolBar * m_wndFullScreenBar; //全屏幕顯示時的浮動工具條
成員函數:
void OnMenuFullscreen(); //全屏幕顯示的處理函數
void OnGetMinMaxInfo(); //捕獲WM_GETMINMAXINFO消息以便允許你增加窗口大小
void OnUpdateViewFullScreen(); //更新“全屏幕顯示”菜單的狀態
源碼
if (m_bFullScreen)
{//全屏幕顯示模式
//隱藏工具條和狀態條
m_wndStatusBar.ShowWindow(SW_HIDE);
m_wndToolBar.ShowWindow(SW_HIDE);
//保存正常視圖時的窗口位置信息以便恢復原來狀態
GetWindowPlacement (&m_wpPrev);
m_wpPrev.length = sizeof m_wpPrev;
//調整RECT為新的窗口尺寸
::GetWindowRect ( ::GetDesktopWindow(), &rectDesktop );
::AdjustWindowRectEx(&rectDesktop, GetStyle(), TRUE, GetExStyle());
//保存RECT以便OnGetMinMaxInfo()使用
m_FullScreenWindowRect = rectDesktop;
wpNew = m_wpPrev;
wpNew.showCmd = SW_SHOWNORMAL;
wpNew.rcNormalPosition = rectDesktop;
//生成新的工具條
m_wndFullScreenBar=new CToolBar;
if(!m_wndFullScreenBar->Create(this, CBRS_SIZE_DYNAMIC|CBRS_FLOATING)
|| !m_wndFullScreenBar->LoadToolBar(IDR_FULLSCREEN))
{
TRACE0("Failed to create toolbar\n");
return; // fail to create
}
m_bFullScreen=FALSE;
//恢復工具條和狀態條
m_wndStatusBar.ShowWindow(SW_SHOWNORMAL);
m_wndToolBar.ShowWindow(SW_SHOWNORMAL);
wpNew = m_wpPrev;
}
//設置窗口顯示狀態
SetWindowPlacement ( &wpNew );
}
void CMainFrame::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
{
if (m_bFullScreen)
{
lpMMI->ptMaxSize.y = m_FullScreenWindowRect.Height();
lpMMI->ptMaxTrackSize.y = lpMMI->ptMaxSize.y;
lpMMI->ptMaxSize.x = m_FullScreenWindowRect.Width();
lpMMI->ptMaxTrackSize.x = lpMMI->ptMaxSize.x;
}
}
void CMainFrame::OnUpdateMenuFullscreen(CCmdUI* pCmdUI)
{//更新菜單的狀態
pCmdUI->Enable();
pCmdUI->SetCheck(m_bFullScreen);
}