全屏显示在许多应用程序中都得到了应用。实现此功能的原理很简单:CWnd类中MoveWindow()函数可以按照指定参数来显示窗口。在执行窗口最大化以前利用GetWindowPlacement()函数先把窗口的当前位置保存在一个变量中,执行窗口最大化后可以通过SetWindowPlacement()函数调用此变量来恢复窗口。利用RepositionBars()函数取得应用程序客户区不被工具条掩盖的大小,GetWindowRect()函数取得应用程序窗口的大小,根据两者之间的关系和屏幕分辨率的尺寸来确定MoveWindow()函数的参数以达到屏幕最大化。
实现步骤如下:
(1) 在Frame/Dialog类中增加以下变量:
WINDOWPLACEMENT prePlacement;
CRect m_FSRect;
BOOL m_bFullScreen;
(2) 全屏设置代码:
void CMainFrame::OnFullscreen()
{
// TODO: Add your command handler code here
GetWindowPlacement(&prePlacement);
CRect m_RectOfCurrentWindow,m_RectOfClient;
GetWindowRect(&m_RectOfCurrentWindow);
RepositionBars(0,0xffff,AFX_IDW_PANE_FIRST,reposQuery,&m_RectOfClient);
ClientToScreen(&m_RectOfClient);
int nFullWidth = GetSystemMetrics(SM_CXSCREEN);
int nFullHeight = GetSystemMetrics(SM_CYSCREEN);
m_FSRect.left = m_RectOfCurrentWindow.left-m_RectOfClient.left;
m_FSRect.top = m_RectOfCurrentWindow.top - m_RectOfClient.top;
m_FSRect.right = m_RectOfCurrentWindow.right - m_RectOfClient.right+nFullWidth;
m_FSRect.bottom = m_RectOfCurrentWindow.bottom - m_RectOfClient.bottom + nFullHeight;
m_bFullScreen = TRUE;
MoveWindow(&m_FSRect,TRUE);
}
(3) (Nono Border Dialog可省略)对CMainFrame类进行Add Windows Message Handler操作,弹出消息选择对话框,对WM_GETMINMAXINFO消息添加消息响应函数。其实现代码如下:
void CMainFrame::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
{
// TODO: Add your message handler code here and/or call default
lpMMI->ptMaxTrackSize.x = 2*GetSystemMetrics(SM_CXSCREEN);
lpMMI->ptMaxTrackSize.y = 2*GetSystemMetrics(SM_CYSCREEN);
CFrameWnd::OnGetMinMaxInfo(lpMMI);
}
*屏幕分辨率
GetSystemMetrics(SM_CXSCREEN); //X轴方向
GetSystemMetrics(SM_CYSCREEN); //Y轴方向