案例4:全屏显示

上传人:kms****20 文档编号:51435439 上传时间:2018-08-14 格式:PPT 页数:33 大小:146.50KB
返回 下载 相关 举报
案例4:全屏显示_第1页
第1页 / 共33页
案例4:全屏显示_第2页
第2页 / 共33页
案例4:全屏显示_第3页
第3页 / 共33页
案例4:全屏显示_第4页
第4页 / 共33页
案例4:全屏显示_第5页
第5页 / 共33页
点击查看更多>>
资源描述

《案例4:全屏显示》由会员分享,可在线阅读,更多相关《案例4:全屏显示(33页珍藏版)》请在金锄头文库上搜索。

1、案例4:全屏显示*1 成都信息工程学院 计算机学院VC+程序设计 需求与目标n全屏显示是一些应用软件程序必不可少的 功能。n在用VC+编辑源文件或编辑对话框等资源 时,选择菜单“View/Full Screen”,即可进 入全屏显示状态,按下取消全屏显示按钮 后会退出全屏显示状态。Date2 成都信息工程学院 计算机学院VC+程序设计 思路n可以通过设置主窗口的位置和大小来大道 目的n关键之处就是要准确地计算出在主窗口的 位置和大小为多少的情况下,才可以是视 图充满整个屏幕,而包括控制条在内的所 以其它界面成分都不可见Date3 成都信息工程学院 计算机学院VC+程序设计 思路n进入全屏显示时

2、候:n记录下当前窗口位置、大小n获得窗口分辨率n重设窗口位置、大小n退出全屏显示时候:n将窗口位置、大小设为先前保存的状态Date4 成都信息工程学院 计算机学院VC+程序设计 编程步骤(1)n用AppWizard建立一个SDI(单文档)工程Date5 成都信息工程学院 计算机学院VC+程序设计 编程步骤(2)n在CMainFrame类中,增加2个成员变量:nCRect m_rcOld;nBOOL m_bFullScreen;n在构造函数中初始化:nm_bFullScreen = FALSE;Date6 成都信息工程学院 计算机学院VC+程序设计 编程步骤(3)n在资源编辑器中编辑菜单IDR_

3、MAINFRAMEn在“查看”菜单栏下添加菜单项“全屏显示”n在其属性框中,ID设置为 ID_VIEW_FULL_SCREENDate7 成都信息工程学院 计算机学院VC+程序设计 编程步骤(3)Date8 成都信息工程学院 计算机学院VC+程序设计 编程步骤(4)n在CMainFrame类增加前述菜单项 ID_VIEW_FULL_SCREEN的消息响应函数nOnViewFullscreen()Date9 成都信息工程学院 计算机学院VC+程序设计 编程步骤(4)Date10 成都信息工程学院 计算机学院VC+程序设计 编程步骤(4)n在消息响应函数中添加代码:nvoid CMainFrame

4、:OnViewFullscreen() nnif(m_bFullScreen)nSetFullScreen(FALSE);nelsenSetFullScreen(TRUE);nDate11 成都信息工程学院 计算机学院VC+程序设计 编程步骤(5)n在CMainFrame类中增加SetFullScreen函数 来切换全屏显示nvoid SetFullScreen(BOOL bFull)nnif(TRUE = bFull)n进入全屏显示nelsen退出全屏显示nm_bFullScreen = bFull; / 改变标记nDate12 成都信息工程学院 计算机学院VC+程序设计 if(TRUE =

5、 bFull)n/ 保存窗口现有位置nGetWindowRect(m_rcOld);n/ 隐藏状态条nm_wndStatusBar.ShowWindow(SW_HIDE);Date13 成都信息工程学院 计算机学院VC+程序设计 CStatusBar m_wndStatusBarn窗口下方的状态条Date14 成都信息工程学院 计算机学院VC+程序设计 CWnd:ShowWindow nBOOL ShowWindow( int nCmdShow );nSets the visibility state of the window. nnCmdShownSpecifies how the CWn

6、d is to be shown. It must be one of the following values:nSW_HIDE nHides this window and passes activation to another window.nSW_SHOW nActivates the window and displays it in its current size and position.nDate15 成都信息工程学院 计算机学院VC+程序设计 if(TRUE = bFull)n/ 去掉窗口的WS_CAPTION样式,否则不 能完全变成全屏显示nLONG style = :

7、GetWindowLong(m_hWnd, GWL_STYLE);nstyle n:SetWindowLong(m_hWnd, GWL_STYLE, style);Date16 成都信息工程学院 计算机学院VC+程序设计 GetWindowLongnLONG GetWindowLong( nHWND hWnd, / handle of window nint nIndex / offset of value to retrieve ); nhWnd nHandle to the window and, indirectly, the class to which the window belo

8、ngs. nnIndex nGWL_STYLE : Retrieves the window styles. nRemarksnThe GetWindowLong function retrieves information about the specified window. The function also retrieves the 32-bit (long) value at the specified offset into the extra window memory of a window. Date17 成都信息工程学院 计算机学院VC+程序设计 SetWindowLon

9、g nLONG SetWindowLong( nHWND hWnd, / handle of windownint nIndex, / offset of value to setnLONG dwNewLong / new value ); nhWnd nHandle to the window and, indirectly, the class to which the window belongs. nnIndex n(同GetWindowLong)ndwNewLong nSpecifies the replacement value.Date18 成都信息工程学院 计算机学院VC+程序

10、设计 if(TRUE = bFull)n/ 取得屏幕的宽度和高度nint nWidth = GetSystemMetrics(SM_CXSCREEN);nint nHeight = GetSystemMetrics(SM_CYSCREEN);nint nBorderWidth = GetSystemMetrics(SM_CXBORDER);nint nBorderHeight = GetSystemMetrics(SM_CYBORDER);Date19 成都信息工程学院 计算机学院VC+程序设计 GetSystemMetrics nint GetSystemMetrics( int nInde

11、x); nnIndex nSpecifies the system metric or configuration setting to retrieve.nSM_CXSCREEN, SM_CYSCREEN nWidth and height, in pixels, of the screen of the primary display monitor. nSM_CXBORDER, SM_CYBORDER nWidth and height, in pixels, of a window border. nDate20 成都信息工程学院 计算机学院VC+程序设计 if(TRUE = bFul

12、l)n/ 计算窗口的新位置nCRect rcWindow;nrcWindow.left = -nBorderWidth * 2 - 2;nrcWindow.right = nWidth + nBorderWidth + 2;nrcWindow.top = -nBorderHeight * 2 - 2;nrcWindow.bottom = nHeight + nBorderHeight + 2;Date21 成都信息工程学院 计算机学院VC+程序设计 if(TRUE = bFull)n/ 设置窗口位置nSetWindowPos(nNULL,nrcWindow.left,nrcWindow.top

13、,nrcWindow.Width(),nrcWindow.Height(),nSWP_NOZORDER);nRecalcLayout();Date22 成都信息工程学院 计算机学院VC+程序设计 CWnd:SetWindowPos nBOOL SetWindowPos(nconst CWnd* pWndInsertAfter,nint x, int y, int cx, int cy,nUINT nFlags );npWndInsertAfternIdentifies the CWnd object that will precede this CWnd object in the Z-ord

14、er.nx, y : left, topncx, cy : width, heightnnFlagsnSpecifies sizing and positioning options.nSWP_NOZORDER Retains current ordering (ignores pWndInsertAfter).nDate23 成都信息工程学院 计算机学院VC+程序设计 CFrameWnd:RecalcLayout nvirtual void RecalcLayout( BOOL bNotify = TRUE ); nbNotifynDetermines whether the active

15、in-place item for the frame window receives notification of the layout change. If TRUE, the item is notified; otherwise FALSE.n它是用来将Toolbar、DialogBar等可浮动的东西 安排位置、处理和View、Frame之间的位置关系 的,例如你直接用 m_wndToolbar.ShowWindow(WM_HIDE)隐藏了 工具条,那就最好调用这个函数重新安排一下剩 下的Bar和View之间的位置 Date24 成都信息工程学院 计算机学院VC+程序设计 elsen

16、LONG style = :GetWindowLong(m_hWnd, GWL_STYLE);nstyle |= WS_CAPTION;n:SetWindowLong(m_hWnd, GWL_STYLE, style);nMoveWindow(m_rcOld);nRecalcLayout();Date25 成都信息工程学院 计算机学院VC+程序设计 调整全屏标志nm_bFullScreen = bFull;Date26 成都信息工程学院 计算机学院VC+程序设计 调试运行n现在已经可以完成进入、退出全屏显示了Date27 成都信息工程学院 计算机学院VC+程序设计 编程步骤(6)n添加是否全屏的标志n在CMainFrame类增加菜单项 ID_VIEW_FULL_SCREEN的界面更新函数nOnUpdateViewFullscreen(CCmdUI* pCmdUI) Date28 成都信息

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 生活休闲 > 科普知识

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号