窗口全屏显示与还原--上位机VC
窗口全屏显示与还原--上位机VC
功能展示
VC6具有窗口全屏显示方便进行资源的编辑功能,我们当前例程也实现窗口全屏显示与还原功能,效果如图,当前是基于对话框的全屏效果,点击按钮,窗口全屏显示,再次点击,窗口还原到原先位置
要点提示
窗口全屏显示可以调用函数 SetWindowPlacement ()实现,为了可以还原窗口原先位置与大小,例程在全屏前利用函数GetWindowPlacement()保存了窗口的位置信息,还原时再次调用函数SetWindowPlacement()进行还原; 实现功能 1.新建基于对话框的应用程序 2.添加变量BOOL m_bFullScreen;//标识全屏与否 WINDOWPLACEMENT m_wpPrev;//保存正常状态窗口位置信息 CRect m_FullScreenWindowRect; 并初始化 m_bFullScreen=FALSE;
3.添加按钮<窗口全屏/还原>关联点击函数 - void CGkbc8Dlg::OnButton1()
- {
- RECT rectDesktop;
- WINDOWPLACEMENT wpNew;
- if (!m_bFullScreen)
- {
- GetWindowPlacement (&m_wpPrev);// We'll need these to restore the original state.
- m_wpPrev.length = sizeof(m_wpPrev);
-
- //Adjust RECT to new size of window
- ::GetWindowRect ( ::GetDesktopWindow(), &rectDesktop );
- ::AdjustWindowRectEx(&rectDesktop, GetStyle(), TRUE, GetExStyle());
- m_FullScreenWindowRect = rectDesktop;// Remember this for OnGetMinMaxInfo()
-
- wpNew = m_wpPrev;
- wpNew.showCmd = SW_SHOWNORMAL;
- wpNew.rcNormalPosition = rectDesktop;
- m_bFullScreen=TRUE;
- }
- else
- {
- m_bFullScreen=FALSE;
- wpNew = m_wpPrev;
- }
- SetWindowPlacement ( &wpNew );//还原窗口位置
- }
复制代码4.添加OnGetMinMaxInfo()还可以添加鼠标点击函数实现拖动窗口 - void CGkbc8Dlg::OnLButtonDown(UINT nFlags, CPoint point)
- {
- if(!m_bFullScreen)PostMessage(WM_NCLBUTTONDOWN,HTCAPTION,0);
- CDialog::OnLButtonDown(nFlags, point);
- }
- void CGkbc8Dlg::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;
- }
- CDialog::OnGetMinMaxInfo(lpMMI);
- }
复制代码我们来演示下功能实现的整个过程
如果您认可,可联系功能定制! 如果您着急,充值会员可直接联系发您资料!
|