资源描述:
《modal dialogs:模态对话框》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、ModalDialogsModaldialogs:mustbedismissedbyuserbeforeanyworkcanbedoneoutsidethedialoginthesameapplication.(Butyoucanworkinanotherapplication).Systemmodal:can'tevenclicktoanotherapplication(example,theControl-Alt-Deletedialog).Modeless:dialogcanstayupwhileyouworkelsewhere(example,toolbarsor
2、toolpalettes).Purposesofmodaldialogs:·collectdatafromuser·presentdatatotheuser·permitusertocontrolapplicationdataModaldialogsareusedwithanordinarySDIorMDIapplication.Whenyouchoosea“dialog-based”application,yourmainwindowsisadialogboxthatisneverdismissed.Thisisnotamodaldialog.Ofcourse,such
3、anapplicationcanalsomakeuseofmodaldialogs,butthemainwindowisnotamodaldialog.ExampleLet’smakethesimplestpossibledialogbox,withjusttwocontrols,tolettheuserspecifytheheightandwidthofarectangle.TheninOnDrawwewilldrawarectangleinthespecifiedsize.MakeanewSDIapplicationcalledRectangleDialog.Choo
4、seProject
5、AddResourceandscrolldowntoDialog:SelectDialogandclicktheNewbutton,ordouble-clickDialog.YouwillbethrownintotheDialogEditor,whichweusedinthepreviouslecture.Designyourdialog.Inthiscase,putintwoeditboxes,oneabovetheother,andtwostatictextboxes,toholdthelabelsHeightandWidth.TheIDnumbe
6、rsofthestatictextboxesdonotmatter,asnocodewillinvolvethem.ChangetheIDnumbersoftheeditboxestoIDC_HEIGHTandIDC_WIDTH.Note:thetoolbarreferstoaneditboxasan“EditControl”—buteverybodycallsthem“editboxes”.Similarly,thetoolbarsays“StaticText”,buteveryonecallsita“statictextbox”.Here’sapictureofthe
7、dialogboxinthedialogeditor,afterdraggingthecontrolstothedesiredposition,andchangingthecaptionsofthestatictextboxesontheirpropertysheets:Right-clickyourdialogintheDialogEditor(inablankareathatisnotpartofacontrol).ChooseAddClass.ThatbringsupClassWizard:Giveyourclassaname(RectangleDialog)and
8、notethatthenamesofthe.hand.cppfilearefilledinforyou.ChangethebaseclasstoCDialog—thepictureshowsthedefault,whichisNOTCDialog.Ifyouforgettochangethis,you’llfindoutmuchlaterthatyoudialogdoesn’tworkproperly;thentheeasiestwaytocorrecttheerrorwillbetodeletethewrongdialoga