可扩展的对话框.ppt

上传人:xt****7 文档编号:2841771 上传时间:2019-12-01 格式:PPT 页数:26 大小:123.50KB
返回 下载 相关 举报
可扩展的对话框.ppt_第1页
第1页 / 共26页
可扩展的对话框.ppt_第2页
第2页 / 共26页
可扩展的对话框.ppt_第3页
第3页 / 共26页
点击查看更多>>
资源描述
2019/12/1,成都信息工程学院 计算机学院,1,案例2:可扩展的对话框,2019/12/1,成都信息工程学院 计算机学院,2,需求与目标,这个功能类似QQ的显示聊天记录 当用户要显示一些过多的选择时,对话框自动扩展其大小,将隐藏的部分显示出来,2019/12/1,成都信息工程学院 计算机学院,3,效果,2019/12/1,成都信息工程学院 计算机学院,4,效果,2019/12/1,成都信息工程学院 计算机学院,5,手段,利用CDialog类的SetRect函数来设定对话框的大小,2019/12/1,成都信息工程学院 计算机学院,6,手段,利用CDialog类的SetRect函数来设定对话框的大小 调用MoveWindow函数来实现改变对话框的大小,2019/12/1,成都信息工程学院 计算机学院,7,编程步骤(1),使用AppWizard创建一个基于对话框的应用程序,2019/12/1,成都信息工程学院 计算机学院,8,编程步骤(2),为对话框添加一些控件,2019/12/1,成都信息工程学院 计算机学院,9,编程步骤(2),2019/12/1,成都信息工程学院 计算机学院,10,编程步骤(2),2019/12/1,成都信息工程学院 计算机学院,11,编程步骤(3),为对话框添加3个成员变量: BOOL m_bExpand; / 记录是否已经扩展对话框 UINT m_nExpandedHeight; / 扩展后对话框的高度 UINT m_nNormalHeight; / 扩展前对话框的高度,2019/12/1,成都信息工程学院 计算机学院,12,BOOL,typedef int BOOL; typedef long BOOL; A Boolean value.,2019/12/1,成都信息工程学院 计算机学院,13,UINT,typedef unsigned int UINT; A 16-bit unsigned integer on Windows versions 3.0 and 3.1; a 32-bit unsigned integer on Win32.,2019/12/1,成都信息工程学院 计算机学院,14,编程步骤(4),在对话框的OnInitDialog函数中加入以下代码: m_bExpand = FALSE; CRect rcDlg, rcMarker; GetWindowRect(rcDlg); m_nExpandedHeight = rcDlg.Height(); GetDlgItem(IDC_BORDER)-GetWindowRect(rcMarker); m_nNormalHeight = (rcMarker.top - rcDlg.top); rcDlg.SetRect(rcDlg.left, rcDlg.top, rcDlg.left + rcDlg.Width(), rcDlg.top + m_nNormalHeight); MoveWindow(rcDlg, TRUE);,2019/12/1,成都信息工程学院 计算机学院,15,CWnd:GetWindowRect,void GetWindowRect( LPRECT lpRect ) const; lpRect Points to a CRect object or a RECT structure that will receive the screen coordinates of the upper-left and lower-right corners. Remarks Copies the dimensions of the bounding rectangle of the CWnd object to the structure pointed to by lpRect. The dimensions are given in screen coordinates relative to the upper-left corner of the display screen. The dimensions of the caption, border, and scroll bars, if present, are included.,2019/12/1,成都信息工程学院 计算机学院,16,RECT、 LPRECT,typedef struct tagRECT LONG left; LONG top; LONG right; LONG bottom; RECT, *PRECT, NEAR *NPRECT, FAR *LPRECT;,2019/12/1,成都信息工程学院 计算机学院,17,CRect,class CRect : public tagRECT public: / retrieves the width int Width() const; / returns the height int Height() const; ,2019/12/1,成都信息工程学院 计算机学院,18,CWnd:GetDlgItem,CWnd* GetDlgItem( int nID ) const; nID Specifies the identifier of the control or child window to be retrieved. Return Value A pointer to the given control or child window. If no control with the integer ID given by the nID parameter exists, the value is NULL. The returned pointer may be temporary and should not be stored for later use. Remarks Retrieves a pointer to the specified control or child window in a dialog box or other window. The pointer returned is usually cast to the type of control identified by nID.,2019/12/1,成都信息工程学院 计算机学院,19,控件ID,resource.h #define IDC_BORDER 1000 #define IDC_EXPAND 1001,2019/12/1,成都信息工程学院 计算机学院,20,CRect:SetRect,void SetRect( int x1, int y1, int x2, int y2 ); x1 Specifies the x-coordinate of the upper-left corner. y1 Specifies the y-coordinate of the upper-left corner. x2 Specifies the x-coordinate of the lower-right corner. y2 Specifies the y-coordinate of the lower-right corner. Remarks Sets the dimensions of CRect to the specified coordinates.,2019/12/1,成都信息工程学院 计算机学院,21,CWnd:MoveWindow,void MoveWindow( LPCRECT lpRect, BOOL bRepaint = TRUE ); lpRect The CRect object or RECT structure that specifies the new size and position. bRepaint Specifies whether CWnd is to be repainted. Remarks Changes the position and dimensions. For a top-level CWnd object, the x and y parameters are relative to the upper-left corner of the screen. For a child CWnd object, they are relative to the upper-left corner of the parent windows client area.,2019/12/1,成都信息工程学院 计算机学院,22,编程步骤(5),为“隐藏”按钮添加单击响应函数OnExpand:,2019/12/1,成都信息工程学院 计算机学院,23,编程步骤(5),为“隐藏”按钮添加单击响应函数OnExpand: void CExpandDlgDlg:OnExpand() m_bExpand = !m_bExpand; CRect rcDlg; GetWindowRect(rcDlg);,2019/12/1,成都信息工程学院 计算机学院,24,编程步骤(5),if(m_bExpand) rcDlg.SetRect(rcDlg.left, rcDlg.top, rcDlg.left + rcDlg.Width(), rcDlg.top + m_nExpandedHeight); m_expand.SetWindowText(“隐藏“); else rcDlg.SetRect(rcDlg.left, rcDlg.top, rcDlg.left + rcDlg.Width(), rcDlg.top + m_nNormalHeight); m_expand.SetWindowText(“显示“); MoveWindow(rcDlg, TRUE); ,2019/12/1,成都信息工程学院 计算机学院,25,CWnd:SetWindowText,void SetWindowText( LPCTSTR lpszString ); lpszString Points to a CString object or null-terminated string to be used as the new title or control text. Remarks Sets the windows title to the specified text. If the window is a control, the text within the control is set.,2019/12/1,成都信息工程学院 计算机学院,26,LPCTSTR,A 32-bit pointer to a constant character string that is portable for Unicode and DBCS.,
展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 图纸专区 > 课件教案


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!