VC对话框全屏显示及相应控件位置改变
2014-04-04 00:51
465 查看
四、设计状态下指定对话框以全屏显示
1、手工把它拽成比如1024×768, 然后Alt+V U
2、在*.rc文件中修改,但是单位不一样。
五、用MoveWindow或SetWindowPos全屏对话框
首先计算出客户区的大小GetClientRect();
再计算出整个窗口的大小GetWindowRect();
然后再得到当前屏幕的大小GetSystemMetrics();
最后根据这三个数据进行换算,当客户区为屏幕大小时窗口的位置的大小;
计算完成后调用MoveWindow就可以了。
六、MFC实现全屏功能的代码
很多的播放器都有快捷键控制窗口以全屏幕的方式显示。给应用程序加上全屏幕的功能,并不需要很多的代码,比如给一个基于对话框的应用程序加上全屏功能只需要以下少量代码就可以工作了。
void CShowDemoDlg::FullScreenView(void)
{
RECT rectDesktop;
WINDOWPLACEMENT wpNew;
if (!IsFullScreen())
{
// We'll need these to restore the original state.
GetWindowPlacement (&m_wpPrev);
//Adjust RECT to new size of window
::GetWindowRect ( ::GetDesktopWindow(), &rectDesktop );
::AdjustWindowRectEx(&rectDesktop, GetStyle(), FALSE, GetExStyle());
// Remember this for OnGetMinMaxInfo()
m_rcFullScreenRect = rectDesktop;
wpNew = m_wpPrev;
wpNew.showCmd = SW_SHOWNORMAL;
wpNew.rcNormalPosition = rectDesktop;
m_bFullScreen=true;
}
else
{
// 退出全屏幕时恢复到原来的窗口状态
m_bFullScreen=false;
wpNew = m_wpPrev;
}
SetWindowPlacement ( &wpNew );
}
bool CShowDemoDlg::IsFullScreen(void)
{
// 记录窗口当前是否处于全屏状态
return m_bFullScreen;
}
void CShowDemoDlg::OnGetMinMaxInfo(MINMAXINFO* lpMMI)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
if (IsFullScreen())
{
lpMMI->ptMaxSize.y = m_rcFullScreenRect.Height();
lpMMI->ptMaxTrackSize.y = lpMMI->ptMaxSize.y;
lpMMI->ptMaxSize.x = m_rcFullScreenRect.Width();
lpMMI->ptMaxTrackSize.x = lpMMI->ptMaxSize.x;
}
CDialogEx::OnGetMinMaxInfo(lpMMI);
}
七、VC实现全屏窗口的一些方法
1.
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);
}
一、简单对话框全屏显示方法 在OnInitDialog()中任意加入: 1、ModifyStyle(WS_CAPTION,0,0); //如果不想去掉标题栏,去掉该句。 SendMessage(WM_SYSCOMMAND,SC_MAXIMIZE,0); 2、ShowWindow(SW_SHOWMAXIMIZED); 二、复杂一点的对话框全屏显示方法,随屏幕的分辩率而调节
void CMainFrame::OnFullScreen() { 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; //设置全屏显示标志为TRUE //进入全屏显示状态 WINDOWPLACEMENT wndpl; wndpl.length=sizeof(WINDOWPLACEMENT); wndpl.flags=0; wndpl.showCmd=SW_SHOWNORMAL; wndpl.rcNormalPosition=m_FullScreenRect; SetWindowPlacement(&wndpl); }
三、对话框全屏及按钮控件移到相应位置 void CXXXDlg::OnLButtonDown(UINT nFlags, CPoint point) { int cx=::GetSystemMetrics(SM_CXSCREEN); int cy=::GetSystemMetrics(SM_CYSCREEN); CRect rtClient,rtBtn; CWnd *pWnd=GetDlgItem(IDC_BUTTON); GetClientRect(&rtClient); //获得对话框客户区屏幕坐标 ClientToScreen(&rtClient); //映射为屏幕坐标 pWnd->GetWindowRect(&rtBtn); //获得button屏幕坐标 int lx=rtBtn.Width(); //button长度 int ly=rtBtn.Height(); //button高度 int dx=rtClient.right-rtBtn.right; //离右边框的距离 int dy=rtClient.bottom-rtBtn.bottom; //离底边框的距离 MoveWindow(CRect(0,0,cx,cy)); //移动窗口 pWnd->MoveWindow(CRect(cx-dx-lx,cy-ly-dy,cx-dx,cy-dy)); //移动button CDialog::OnLButtonDown(nFlags, point); }
四、设计状态下指定对话框以全屏显示
1、手工把它拽成比如1024×768, 然后Alt+V U
2、在*.rc文件中修改,但是单位不一样。
五、用MoveWindow或SetWindowPos全屏对话框
首先计算出客户区的大小GetClientRect();
再计算出整个窗口的大小GetWindowRect();
然后再得到当前屏幕的大小GetSystemMetrics();
最后根据这三个数据进行换算,当客户区为屏幕大小时窗口的位置的大小;
计算完成后调用MoveWindow就可以了。
六、MFC实现全屏功能的代码
很多的播放器都有快捷键控制窗口以全屏幕的方式显示。给应用程序加上全屏幕的功能,并不需要很多的代码,比如给一个基于对话框的应用程序加上全屏功能只需要以下少量代码就可以工作了。
void CShowDemoDlg::FullScreenView(void)
{
RECT rectDesktop;
WINDOWPLACEMENT wpNew;
if (!IsFullScreen())
{
// We'll need these to restore the original state.
GetWindowPlacement (&m_wpPrev);
//Adjust RECT to new size of window
::GetWindowRect ( ::GetDesktopWindow(), &rectDesktop );
::AdjustWindowRectEx(&rectDesktop, GetStyle(), FALSE, GetExStyle());
// Remember this for OnGetMinMaxInfo()
m_rcFullScreenRect = rectDesktop;
wpNew = m_wpPrev;
wpNew.showCmd = SW_SHOWNORMAL;
wpNew.rcNormalPosition = rectDesktop;
m_bFullScreen=true;
}
else
{
// 退出全屏幕时恢复到原来的窗口状态
m_bFullScreen=false;
wpNew = m_wpPrev;
}
SetWindowPlacement ( &wpNew );
}
bool CShowDemoDlg::IsFullScreen(void)
{
// 记录窗口当前是否处于全屏状态
return m_bFullScreen;
}
void CShowDemoDlg::OnGetMinMaxInfo(MINMAXINFO* lpMMI)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
if (IsFullScreen())
{
lpMMI->ptMaxSize.y = m_rcFullScreenRect.Height();
lpMMI->ptMaxTrackSize.y = lpMMI->ptMaxSize.y;
lpMMI->ptMaxSize.x = m_rcFullScreenRect.Width();
lpMMI->ptMaxTrackSize.x = lpMMI->ptMaxSize.x;
}
CDialogEx::OnGetMinMaxInfo(lpMMI);
}
七、VC实现全屏窗口的一些方法
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);
}
相关文章推荐
- VC对话框全屏显示及相应控件位置改变(转)
- VC对话框全屏显示及相应控件位置改变
- VC对话框全屏显示及相应控件位置改变
- VC对话框全屏显示及相应控件位置改变(转)
- VC对话框全屏显示及相应控件位置改变(转)
- VC对话框全屏显示及相应控件位置改变(转)
- VC对话框全屏显示及相应控件位置改变(转)
- VC对话框全屏显示及相应控件位置改变
- VC对话框全屏显示及相应控件位置改变
- VC对话框全屏显示及相应控件位置改变
- VC对话框全屏显示及相应控件位置改变
- VC对话框全屏显示及相应控件位置改变
- VC对话框全屏显示及相应控件位置改变(转)
- VC对话框全屏显示及相应控件位置改变(转)
- VC对话框加载图片、改变背景颜色、画图、显示隐藏控件
- VC++对话框(CDialog)的全屏显示及控件居中显示
- VC改变控件或对话框的大小和位置方法
- VC6里改变对话框资源ID号后classwizard不能正常显示控件ID的原因及解决方法
- 改变对话框尺寸,使得控件位置和显示区域动态改变
- C# WinForm 改变控件在窗体上的显示位置