1.
void CXXXDlg::SetFullScreen() { int frameWidth = GetSystemMetrics(SM_CXFRAME); int frameHeight = GetSystemMetrics(SM_CYFRAME); int captionHeight = GetSystemMetrics(SM_CYCAPTION); int screenWidth = GetSystemMetrics(SM_CXSCREEN); int screenHeight = GetSystemMetrics(SM_CYSCREEN); CRect rect; GetClientRect(&rect); rect.left = rect.left - frameWidth; rect.top = rect.top - frameHeight - captionHeight ; rect.bottom = rect.top + screenHeight + 2 * frameHeight + captionHeight; rect.right = rect.left + screenWidth + 2 * frameWidth; ShowWindow(SW_HIDE); SetWindowPos(&wndTopMost, rect.left, rect.top, rect.Width(), rect.Height(), SWP_SHOWWINDOW); }
>>>VC++来实现全屏幕显示功能
2.
实现全屏显示:
在CMainFrame类中实现
private:
BOOL m_bFullScreen; // 全屏显示标志
WINDOWPLACEMENT m_OldWndPlacement; // 用来保存原窗口的位置
CRect m_FullScreenRect; // 表示全屏显示时的窗口位置
初始化
CMainFrame::CMainFrame()
{
// TODO: add member initialization code here
m_bFullScreen = FALSE;
}
添加菜单项以及菜单效应函数
void CMainFrame::OnFullScreen()
{
// TODO: Add your command handler code here
GetWindowPlacement(&m_OldWndPlacement);
CRect WindowRect;
GetWindowRect(&WindowRect);
CRect ClientRect;
RepositionBars(0, 0xffff, AFX_IDW_PANE_FIRST, reposQuery, &ClientRect);
ClientToScreen(&ClientRect);
// 获取屏幕的分辨率
int nFullWidth = GetSystemMetrics(SM_CXSCREEN);
int nFullHeight = GetSystemMetrics(SM_CYSCREEN);
// 将出控制条外的客户区全屏显示到从(0,0)到(nFullWidth,nFullHeight)区域
// 将(0,0)和(nFullWidth,nFullHeight)两个点外扩充原窗口和控制条之外的
// 客户区位置间的差值,就得到全屏显示的窗口位置
m_FullScreenRect.left = WindowRect.left - ClientRect.left;
m_FullScreenRect.top = WindowRect.top - ClientRect.top;
m_FullScreenRect.right = WindowRect.right - ClientRect.right + nFullWidth;
m_FullScreenRect.bottom = WindowRect.bottom - ClientRect.bottom + nFullHeight;
m_bFullScreen = TRUE; // 设置全屏显示标志为TURE
WINDOWPLACEMENT wndpl;
wndpl.length = sizeof(WINDOWPLACEMENT);
wndpl.flags = 0;
wndpl.showCmd = SW_SHOWNORMAL;
wndpl.rcNormalPosition = m_FullScreenRect;
SetWindowPlacement(&wndpl);
}
void CMainFrame::OnUpdateFullScreen(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
if (m_bFullScreen)
{
pCmdUI->SetCheck(1);
}
else
{
pCmdUI->SetCheck(0);
}
}
重载CMainFrame类的OnGetMinMaxInfo()函数
void CMainFrame::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)
{
// TODO: Add your message handler code here and/or call default
if (m_bFullScreen)
{
lpMMI->ptMaxSize.x = m_FullScreenRect.Width();
lpMMI->ptMaxSize.y = m_FullScreenRect.Height();
lpMMI->ptMaxPosition.x = m_FullScreenRect.Width();
lpMMI->ptMaxPosition.y = m_FullScreenRect.Height();
//最大的Track尺寸也要改变
lpMMI->ptMaxTrackSize.x = m_FullScreenRect.Width();
lpMMI->ptMaxTrackSize.y = m_FullScreenRect.Height();
}
CMDIFrameWnd::OnGetMinMaxInfo(lpMMI);
}
在类CMainFrame中添加函数EndFullScreen()。
void CMainFrame::EndFullScreen()
{
if (m_bFullScreen)
{
// 推出全屏显示,恢复原始窗口显示
ShowWindow(SW_HIDE);
SetWindowPlacement(&m_OldWndPlacement);
}
}
下面实现在按下Esc键时,调用EndFullScreen()函数。也即:建立按键与函数之间的联系
// 添加WM_KEYDOWN消息相应函数
void CFullScreenTestView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
if (nChar == VK_ESCAPE) // 如果按下的是Esc键
{
// 获取主窗口指针
CMainFrame* pFrame = (CMainFrame*) AfxGetApp()->m_pMainWnd;
// 调用主窗口类的自定义函数EndFullScreen(),便可以退出全屏显示模式
pFrame->EndFullScreen();
}
CView::OnKeyDown(nChar, nRepCnt, nFlags);
}