版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、2020/8/15,成都信息工程学院 计算机学院,1,案例2:可扩展的对话框,2020/8/15,成都信息工程学院 计算机学院,2,需求与目标,这个功能类似QQ的显示聊天记录 当用户要显示一些过多的选择时,对话框自动扩展其大小,将隐藏的部分显示出来,2020/8/15,成都信息工程学院 计算机学院,3,效果,2020/8/15,成都信息工程学院 计算机学院,4,效果,2020/8/15,成都信息工程学院 计算机学院,5,手段,利用CDialog类的SetRect函数来设定对话框的大小,2020/8/15,成都信息工程学院 计算机学院,6,手段,利用CDialog类的SetRect函数来设定对话
2、框的大小 调用MoveWindow函数来实现改变对话框的大小,2020/8/15,成都信息工程学院 计算机学院,7,编程步骤(1),使用AppWizard创建一个基于对话框的应用程序,2020/8/15,成都信息工程学院 计算机学院,8,编程步骤(2),为对话框添加一些控件,2020/8/15,成都信息工程学院 计算机学院,9,编程步骤(2),2020/8/15,成都信息工程学院 计算机学院,10,编程步骤(2),2020/8/15,成都信息工程学院 计算机学院,11,编程步骤(3),为对话框添加3个成员变量: BOOL m_bExpand; / 记录是否已经扩展对话框 UINT m_nExp
3、andedHeight; / 扩展后对话框的高度 UINT m_nNormalHeight; / 扩展前对话框的高度,2020/8/15,成都信息工程学院 计算机学院,12,BOOL,typedef int BOOL; typedef long BOOL; A Boolean value.,2020/8/15,成都信息工程学院 计算机学院,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.
4、,2020/8/15,成都信息工程学院 计算机学院,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, rcDl
5、g.left + rcDlg.Width(), rcDlg.top + m_nNormalHeight); MoveWindow(rcDlg, TRUE);,2020/8/15,成都信息工程学院 计算机学院,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 corn
6、ers. 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 inclu
7、ded.,2020/8/15,成都信息工程学院 计算机学院,16,RECT、 LPRECT,typedef struct tagRECT LONG left; LONG top; LONG right; LONG bottom; RECT, *PRECT, NEAR *NPRECT, FAR *LPRECT;,2020/8/15,成都信息工程学院 计算机学院,17,CRect,class CRect : public tagRECT public: / retrieves the width int Width() const; / returns the height int Height(
8、) const; ,2020/8/15,成都信息工程学院 计算机学院,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
9、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.,2020/8/15,成都信息工程学院 计算机学院,1
10、9,控件ID,resource.h #define IDC_BORDER 1000 #define IDC_EXPAND 1001,2020/8/15,成都信息工程学院 计算机学院,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
11、 the lower-right corner. y2 Specifies the y-coordinate of the lower-right corner. Remarks Sets the dimensions of CRect to the specified coordinates.,2020/8/15,成都信息工程学院 计算机学院,21,CWnd:MoveWindow,void MoveWindow( LPCRECT lpRect, BOOL bRepaint = TRUE ); lpRect The CRect object or RECT structure that spe
12、cifies 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 cor
13、ner of the parent windows client area.,2020/8/15,成都信息工程学院 计算机学院,22,编程步骤(5),为“隐藏”按钮添加单击响应函数OnExpand:,2020/8/15,成都信息工程学院 计算机学院,23,编程步骤(5),为“隐藏”按钮添加单击响应函数OnExpand: void CExpandDlgDlg:OnExpand() m_bExpand = !m_bExpand; CRect rcDlg; GetWindowRect(rcDlg);,2020/8/15,成都信息工程学院 计算机学院,24,编程步骤(5),if(m_bExpand)
14、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); ,2020/8/15,成都信息工程学院 计算机学院,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 Set
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026湖南怀化国际陆港经济开发区内国有企业招聘4人考试备考题库附答案
- 2026玉溪师范学院附属实验学校、玉溪师范学院附属小学区外人才引进(28人)备考题库附答案
- 2026福建厦门市集美区双岭小学产假顶岗教师招聘1人备考题库附答案
- 2026福建省网络与信息安全测评中心招聘驾驶员2人备考题库附答案
- 2026福建福州市中医院招聘1名编外眼科护理考试备考题库附答案
- 2026西安市某电力系统外包项目充电设施运维人员招聘备考题库附答案
- 2026贵州湄潭县纪委县监委选调事业单位工作人员备考题库附答案
- 2026重庆两江新区鸳鸯社区卫生服务中心招聘1人参考题库附答案
- 2026陕西宝鸡市科技创新交流服务中心招聘高层次人才3人备考题库附答案
- 2026陕西集团龙钢公司供销中心一般管理岗位竞聘24人参考题库附答案
- 工作计划考核管理办法
- 语义地图构建方法-深度研究
- 江苏省南通市2025届高三第一次调研测试数学试题(南通一模)(含解析)
- 《肝性脑病护理》课件
- 五年级下册语文寒假预习古诗、古文、日积月累背诵单
- DB33 642-2019 热电联产能效、能耗限额及计算方法
- GB/T 4074.7-2024绕组线试验方法第7部分:测定漆包绕组线温度指数的试验方法
- 海参供货合同范例
- DB41T 1448-2017 湿式堆存尾矿库安全技术规程
- GB/T 22081-2024网络安全技术信息安全控制
- 江苏南京市、盐城市2025届高二上数学期末教学质量检测试题含解析
评论
0/150
提交评论