博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
MFC中视图的全屏显示
阅读量:4109 次
发布时间:2019-05-25

本文共 3068 字,大约阅读时间需要 10 分钟。

[转载自:http://www.sudu.cn/info/html/edu/20080403/260953.html]

我们经常会在程序中提供一个全屏显示的功能,如何实现呢?

第一步:声明FullScreenHandler类。

#ifndef __FullScreenHandler_h__#define __FullScreenHandler_h__class CFullScreenHandler{ public:    CFullScreenHandler();    ~CFullScreenHandler();    void Maximize(CFrameWnd* pFrame, CWnd* pView);    void Restore(CFrameWnd* pFrame);    BOOL InFullScreenMode() {  return !m_rcRestore.IsRectEmpty();  }    CSize GetMaxSize();protected:    CRect m_rcRestore;};#endif  //__FullScrennHandler_h__// Global instanceextern CFullScreenHandler FullScreenHandler;
第二步:实现FullScreenHandler类。

#include "FullScreenHandler.h"// Global object handles full-screen modeCFullScreenHandler FullScreenHandler;CFullScreenHandler::CFullScreenHandler(){     m_rcRestore.SetRectEmpty();}CFullScreenHandler::~CFullScreenHandler(){ }//// Resize frame so view’s client area fills the entire screen. Use// GetSystemMetrics to get the screen size -- the rest is pixel// arithmetic.//void CFullScreenHandler::Maximize(CFrameWnd* pFrame, CWnd* pView){     // get view rectangle    if (pView) {         CRect rcv;        pView->GetWindowRect(&rcv);        // get frame rectangle        pFrame->GetWindowRect(m_rcRestore); // save for restore        const CRect& rcf = m_rcRestore;             // frame rect        // now compute new rect        CRect rc(0,0, GetSystemMetrics(SM_CXSCREEN),            GetSystemMetrics(SM_CYSCREEN));        rc.left  += rcf.left  - rcv.left;        rc.top   += rcf.top   - rcv.top;        rc.right += rcf.right - rcv.right;        rc.bottom+= rcf.bottom- rcv.bottom;        // move frame!        pFrame->SetWindowPos(NULL, rc.left, rc.top,            rc.Width(), rc.Height(), SWP_NOZORDER);    }}void CFullScreenHandler::Restore(CFrameWnd* pFrame){     const CRect& rc = m_rcRestore;    pFrame->SetWindowPos(NULL, rc.left, rc.top,        rc.Width(), rc.Height(), SWP_NOZORDER);    m_rcRestore.SetRectEmpty();}CSize CFullScreenHandler::GetMaxSize(){     CRect rc(0,0,        GetSystemMetrics(SM_CXSCREEN),GetSystemMetrics(SM_CYSCREEN));    rc.InflateRect(10,50);    return rc.Size();}

第三步:定义ID_VIEW_FULL_SCREEN资源,响应视图的WM_GETMINMAXINFO消息

CRect m_rcRestore;    afx_msg void OnGetMinMaxInfo(MINMAXINFO* lpmmi);BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)    ON_WM_GETMINMAXINFO()END_MESSAGE_MAP()//// Important to handle this in order to set size// of window larger than whole screen.//void CMainFrame::OnGetMinMaxInfo(MINMAXINFO* lpmmi){     CSize sz = FullScreenHandler.GetMaxSize();    lpmmi->ptMaxSize = CPoint(sz);    lpmmi->ptMaxTrackSize = CPoint(sz);}//// View full screen mode. Calls CFullScreenHandler to do the work.//void CMainFrame::OnViewFullScreen(){     if (FullScreenHandler.InFullScreenMode())        FullScreenHandler.Restore(this);    else        FullScreenHandler.Maximize(this, GetActiveView());        //如果是拆分窗口则应为FullScreenHandler.Maximize(this, m_wndSplitter); }//// Put checkmark next to command if in full screen mode.//void CMainFrame::OnUpdateViewFullScreen(CCmdUI* pCmdUI){     pCmdUI->SetCheck(FullScreenHandler.InFullScreenMode());}
你可能感兴趣的文章
OKhttp之Call接口
查看>>
application/x-www-form-urlencoded、multipart/form-data、text/plain
查看>>
关于Content-Length
查看>>
WebRequest post读取源码
查看>>
使用TcpClient可避免HttpWebRequest的常见错误
查看>>
EntityFramework 学习之一 —— 模型概述与环境搭建 .
查看>>
C# 发HTTP请求
查看>>
初试visual studio2012的新型数据库LocalDB
查看>>
启动 LocalDB 和连接到 LocalDB
查看>>
Palindrome Number --回文整数
查看>>
Reverse Integer--反转整数
查看>>
Container With Most Water --装最多水的容器(重)
查看>>
Longest Common Prefix -最长公共前缀
查看>>
Letter Combinations of a Phone Number
查看>>
Single Number II --出现一次的数(重)
查看>>
Valid Parentheses --括号匹配
查看>>
Generate Parentheses--生成匹配括号(重)
查看>>
Remove Element--原地移除重复元素
查看>>
Remove Duplicates from Sorted Array--从有序数组中移除重复元素
查看>>
Count and Say
查看>>