工控编程吧
标题:
窗口全屏显示与还原--上位机VC
[打印本页]
作者:
qq263946146
时间:
2016-12-6 19:47
标题:
窗口全屏显示与还原--上位机VC
(, 下载次数: 0)
上传
点击文件名下载附件
窗口全屏显示与还原--上位机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);
}
复制代码
我们来演示下功能实现的整个过程
[iqiyi]http://player.video.qiyi.com/5eb6af777f2b9259e57a3d2ca1cd1281/0/0/w_19rujlna5x.swf-albumId=6905394009-tvId=6905394009-isPurchase=0-cnId=12[/iqiyi]
(, 下载次数: 0)
上传
点击文件名下载附件
[weixinlianxi]1[/weixinlianxi]
欢迎光临 工控编程吧 (https://www.gkbc8.com/)
Powered by Discuz! X3.4