源代码如下:
void CMainFrame::SetFullScreenMode(BOOL bFullMode) // 全屏显示
{
if(bFullMode == m_bFullScreenMode)// 当前状态已经是全屏或非全屏状态,直接返回
return;
//m_bToolBarWasVisible = (m_wndToolBar.IsWindowVisible() != 0);
//m_wndToolBar.ShowWindow(!bFullMode);
m_bStatisBarWasVisible = (m_wndStatusBar.IsWindowVisible() != 0);
m_wndStatusBar.ShowWindow(!bFullMode);
// 保存窗口位置
if(bFullMode)
GetWindowRect(&m_MainRect);
else
MoveWindow(m_MainRect);
// 移走或添加主窗口的标题
LONG style = ::GetWindowLong(m_hWnd,GWL_STYLE);
if(bFullMode)
style &= ~WS_CAPTION;
else
style |= WS_CAPTION;
::SetWindowLong(m_hWnd,GWL_STYLE,style);
int cxScreen = GetSystemMetrics(SM_CXSCREEN);
int cyScreen = GetSystemMetrics(SM_CYSCREEN);
if(bFullMode)
{ //设置窗口位置
SetWindowPos(NULL,-2,-2,cxScreen,cyScreen,SWP_NOZORDER);
// 保存最初的菜单,并设置菜单为 NULL
ASSERT(m_OrgMenu.GetSafeHmenu() == NULL);
CMenu *pOldMenu = GetMenu();
m_OrgMenu.Attach(pOldMenu->Detach());
SetMenu((CMenu*)NULL);
// 右侧控制面板
m_wndMyBar1.ShowWindow(SW_HIDE);
m_TabCtrl.ShowWindow(SW_HIDE);
}
else
{
ASSERT(m_OrgMenu.GetSafeHmenu() != NULL);
SetMenu(&m_OrgMenu);
m_OrgMenu.Detach();
// 右侧控制面板
m_wndMyBar1.ShowWindow(SW_SHOW);
m_TabCtrl.ShowWindow(SW_SHOW);
}
// 窗口所有控件重排
RecalcLayout();
m_bFullScreenMode = bFullMode;
}
在View中调用
void CNiKoView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
if(nChar == 'F' || nChar == 'f' || nChar == VK_ESCAPE)
{// 全屏显示控制
CMainFrame *pFrame = (CMainFrame*)AfxGetMainWnd();
if(nChar == 'F' || nChar == 'f' )
pFrame->SetFullScreenMode(TRUE);
else
pFrame->SetFullScreenMode(FALSE);
}
CView::OnChar(nChar, nRepCnt, nFlags);
}