




已阅读5页,还剩21页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
案例2:可扩展的对话框,1,需求与目标,这个功能类似QQ的显示聊天记录当用户要显示一些过多的选择时,对话框自动扩展其大小,将隐藏的部分显示出来,2,效果,3,效果,4,手段,利用CDialog类的SetRect函数来设定对话框的大小,5,手段,利用CDialog类的SetRect函数来设定对话框的大小调用MoveWindow函数来实现改变对话框的大小,6,编程步骤(1),使用AppWizard创建一个基于对话框的应用程序,7,编程步骤(2),为对话框添加一些控件,8,编程步骤(2),9,编程步骤(2),10,编程步骤(3),为对话框添加3个成员变量:BOOLm_bExpand;/记录是否已经扩展对话框UINTm_nExpandedHeight;/扩展后对话框的高度UINTm_nNormalHeight;/扩展前对话框的高度,11,BOOL,typedefintBOOL;typedeflongBOOL;ABooleanvalue.,12,UINT,typedefunsignedintUINT;A16-bitunsignedintegeronWindowsversions3.0and3.1;a32-bitunsignedintegeronWin32.,13,编程步骤(4),在对话框的OnInitDialog函数中加入以下代码:m_bExpand=FALSE;CRectrcDlg,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);,14,CWnd:GetWindowRect,voidGetWindowRect(LPRECTlpRect)const;lpRectPointstoaCRectobjectoraRECTstructurethatwillreceivethescreencoordinatesoftheupper-leftandlower-rightcorners.RemarksCopiesthedimensionsoftheboundingrectangleoftheCWndobjecttothestructurepointedtobylpRect.Thedimensionsaregiveninscreencoordinatesrelativetotheupper-leftcornerofthedisplayscreen.Thedimensionsofthecaption,border,andscrollbars,ifpresent,areincluded.,15,RECT、LPRECT,typedefstructtagRECTLONGleft;LONGtop;LONGright;LONGbottom;RECT,*PRECT,NEAR*NPRECT,FAR*LPRECT;,16,CRect,classCRect:publictagRECTpublic:/retrievesthewidthintWidth()const;/returnstheheightintHeight()const;,17,CWnd:GetDlgItem,CWnd*GetDlgItem(intnID)const;nIDSpecifiestheidentifierofthecontrolorchildwindowtoberetrieved.ReturnValueApointertothegivencontrolorchildwindow.IfnocontrolwiththeintegerIDgivenbythenIDparameterexists,thevalueisNULL.Thereturnedpointermaybetemporaryandshouldnotbestoredforlateruse.RemarksRetrievesapointertothespecifiedcontrolorchildwindowinadialogboxorotherwindow.ThepointerreturnedisusuallycasttothetypeofcontrolidentifiedbynID.,18,控件ID,resource.h#defineIDC_BORDER1000#defineIDC_EXPAND1001,19,CRect:SetRect,voidSetRect(intx1,inty1,intx2,inty2);x1Specifiesthex-coordinateoftheupper-leftcorner.y1Specifiesthey-coordinateoftheupper-leftcorner.x2Specifiesthex-coordinateofthelower-rightcorner.y2Specifiesthey-coordinateofthelower-rightcorner.RemarksSetsthedimensionsofCRecttothespecifiedcoordinates.,20,CWnd:MoveWindow,voidMoveWindow(LPCRECTlpRect,BOOLbRepaint=TRUE);lpRectTheCRectobjectorRECTstructurethatspecifiesthenewsizeandposition.bRepaintSpecifieswhetherCWndistoberepainted.RemarksChangesthepositionanddimensions.Foratop-levelCWndobject,thexandyparametersarerelativetotheupper-leftcornerofthescreen.ForachildCWndobject,theyarerelativetotheupper-leftcorneroftheparentwindowsclientarea.,21,编程步骤(5),为“隐藏”按钮添加单击响应函数OnExpand:,22,编程步骤(5),为“隐藏”按钮添加单击响应函数OnExpand:voidCExpandDlgDlg:OnExpand()m_bExpand=!m_bExpand;CRectrcDlg;GetWindowRect(rcDlg);,23,编程步骤(5),if(m_bExpand)rcDlg.SetRect(rcDlg.left,rcDlg.top,rcDlg.left+rcDlg.Width(),rcDlg.top+m_nExpandedHeight);m_expand.SetWindowText(隐藏);elsercDlg.SetRect(rcDlg.left,rcDlg.top,rcDlg.left+rcDlg.Width(),rcDlg.top+m_nNormalHeight);m_expand.SetWindowText(显示);MoveWindow(rcDlg,TRUE);,24,CWnd:SetWindowText,voidSetWindowText(LPCTSTRlpszString);lpszStringPointstoaCStringobjectornull-terminatedstringtobeusedasthenewtitleorcontroltext.RemarksSets
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年年物业管理续约合同范本
- 2025年中外合资经营企业合同(食品加工)范文
- 2025综合销售合同范本
- 火星时代Revit课件
- 医美项目考试题库及答案
- 2025年税务师之税法一考前冲刺模拟试卷A卷含答案
- 2025年施工员市政方向基础+岗位技能考试题库附答案
- 2025标准家居买卖合同样本
- 辅导班入职考试题及答案
- 2025年合作协议书之企业融资合同协议书
- 冀少版(2024新版)七年级上册生物第一单元《生物体的结构层次》1.2《细胞的形态》教案
- 正常人体结构课程标准
- 无人机应用与基础操控入门课件
- 初中语文八年级上册13 唐诗五首 《钱塘湖春行》活动式公开课一等奖创新教学设计
- 职业技能大赛-电工职业技能竞赛理论题库(附参考答案)
- DL∕T 514-2017 电除尘器 标准
- IPO申报财务三年又一期会计报表模板(单体式)
- 急性胰腺炎抗凝治疗
- 美慧树课件教材培训
- 09J202-1 坡屋面建筑构造(一)-1
- 研发人员工时统计表
评论
0/150
提交评论