




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
IntroductionofMFCVisualC++ismuchmorethanacompiler.Itisacompleteapplicationdevelopmentenvironmentthat,whenusedasintended,letsyoufullyexploittheobjectorientednatureofC++tocreateprofessionalWindowsapplications.Inordertotakeadvantageofthesefeatures,youneedtounderstandtheC++programminglanguage.IfyouhaveneverusedC++,pleaseturntotheC++tutorialsintheC/C++Tutorialspageforanintroduction.YoumustthenunderstandtheFoundationClass(MFC)hierarchy.ThisclasshierarchyencapsulatestheuserinterfaceportionoftheWindowsAPI,andmakesitsignificantlyeasiertocreateWindowsapplicationsinanobjectorientedway.ThishierarchyisavailableforandcompatiblewithallversionsofWindows.ThecodeyoucreateinMFCisextremelyportable.ThesetutorialsintroducethefundamentalconceptsandvocabularybehindMFCandeventdrivenprogramming.Inthistutorialyouwillenter,compile,andrunasimpleMFCprogramusingVisualC++.2providesadetailedexnationofthecodeusedinTutorial1.Tutorial3discussesMFCcontrolsandtheircustomization.Tutorial4coversmessagemaps,whichletyouhandleeventsinMFC.WhatistheFoundationsClassLet'ssayyouwanttocreateaWindowsapplication.Youmight,forexample,needtocreateaspecializedtextordrawingeditor,oraprogramthatfindsfilesonalargeharddisk,oranapplicationthatletsauservisualizetheinterrelationshipsinabigdataset.Wheredoyoubegin?Agoodstartingceisthedesignoftheuserinterface.First,decidewhattheusershouldbeabletodowiththeprogramandthenpickasetofuserinterfaceobjectsaccordingly.TheWindowsuserinterfacehasanumberofstandardcontrols,suchasbuttons,s,scrollbars,andliststhatarealreadyfamiliartoWindowsusers.Withthisinmind,theprogrammermustchooseasetofcontrolsanddecidehowtheyshouldbearrangedonscreen.Atime-honoredprocedureistomakearoughsketchoftheproposeduserinterface(bytraditiononanapkinorthebackofanenvelope)andywiththeelementsuntiltheyfeelright.Forsmallprojects,orfortheearlyprototyphaseofalargerproject,thisissufficient.alsoprovidesaC++librarythatsitsontopofanyoftheWindowsAPIsandmakestheprogrammer'sjobeasier.CalledtheFoundationClasslibrary(MFC),thislibrary'sprimaryadvantageisefficiency.ItgreatlyreducestheamountofcodethatmustbewrittentocreateaWindowsprogram.ItalsoprovidesalltheadvantagesnormallyfoundinC++programming,suchasinheritanceandencapsulation.MFCisportable,sothat,forexample,codecreatedunderWindows3.1canmovetoWindowsNTor95veryeasily.MFCisthereforethepreferredmethodfordeveloWindowsapplicationsandwillbeusedthroughoutthesetutorials.WhenyouuseMFC,youwritecodethatcreatesthenecessaryuserinterfacecontrolsandcustomizestheirappearance.Youalsowritecodethatrespondswhentheusermanipulatesthesecontrols.Forexample,iftheuserclicksabutton,youwanttohavecodeincethatrespondsappropriay.Itisthissortofevent-handlingcodethatwillformthebulkofanyapplication.Oncetheapplicationrespondscorrectlytoalloftheavailablecontrols,itisfinished.YoucanseefromthisdiscussionthatthecreationofaWindowsprogramisastraightforwardprocesswhenusingMFC.Thegoalofthesetutorialsistofillinthedetailsandtoshowthetechniquesyoucanusetocreateprofessionalapplicationsasquicklyaspossible.TheVisualC++applicationdevelopmentenvironmentisspecificallytunedtoMFC,sobylearningMFCandVisualC++togetheryoucansignificantlyincreaseyourpowerasanapplicationdeveloper.ThevocabularyusedtotalkaboutuserinterfacefeaturesandsoftwaredevelopmentinWindowsisbasicbutunique.Herewereviewafewdefinitionstomakediscussioneasierforthosewhoarenewtotheenvironment.liveinsidea"framewindow".Aframewindowisafullyfeaturedmainwindowthattheusercanre-size,minimize,izetofillthescreen,andsoon.Windowsalsosupportstwotypesofdialogboxes:modalandmodeless.Amodaldialogbox,onceonthescreen,blocksinputtotherestoftheapplicationuntilitisanswered.Amodelessdialogboxcanappearatthesametimeastheapplicationandseemsto"floatabove"ittokeepfrombeingoverlaid.MostsimpleWindowsapplicationsuseaSingle Interface,orSDI,frame.TheClock,PIFeditor,andNotepadareexamplesofSDIapplications.WindowsalsoprovidesanorganizingschemecalledtheMultiple Interface,orMDIformorecomplicatedapplications.TheMDIsystemallowstheusertoviewmultiplesatthesametimewithinasingleinstanceofanapplication.Forexample,atexteditormightallowtheusertoopenmultiplefilessimultaneously.WhenimplementedwithMDI,theapplicationpresentsalargeapplicationwindowthatcanholdmultiplesub-windows,eachcontaininga.Thesinglemain isheldbythemainapplicationwindowanditappliestothetop-mostwindowheldwithintheMDIframe.IndividualwindowscanbeiconifiedorexpandedasdesiredwithintheMDIframe,ortheentireMDIframecanbeminimizedintoasingleicononthedesktop.TheMDIinterfacegivestheimpressionofaseconddesktopoutonthedesktop,anditgoesalongwaytowardsorganizingandremovingwindowclutter.Eachapplicationthatyoucreatewilluseitsownuniquesetofcontrols,itsownstructure,anditsowndialogboxes.Agreatdealoftheeffortthatgoescreatinganygoodapplicationinterfaceliesinthechoiceandorganizationoftheseinterfaceobjects.VisualC++,alongwithitsresourceeditors,makesthecreationandcustomizationoftheseinterfaceobjectsextremelyeasy.Event-drivenSoftwareandVocabularyAllwindow-basedGUIscontainthesamebasicelementsandalloperateinthesameway.Onscreentheuserseesagroupofwindows,eachofwhichcontainscontrols,icons,objectsandsuchthataremanipulatedwiththemouseorthekeyboard.Theinterfaceobjectsseenbytheuserarethesamefromsystemtosystem:pushbuttons,scrollbars,icons,dialogboxes,pulldowns,etc.Theseinterfaceobjectsallworkthesameway,althoughsomehaveminordifferencesintheir"lookandfeel."Forexample,scrollbarslookslightlydifferentasyoumovefromWindowstotheMactoMotif,buttheyalldothesamething.Fromaprogrammer'sstandpoint,thesystemsareallsimilarinconcept,althoughtheydifferradicallyintheirspecifics.TocreateaGUIprogram,theprogrammerfirstputsalloftheneededuserinterfacecontrolsintoawindow.Forexample,iftheprogrammeristryingtocreateasimpleprogramsuchasaFahrenheittoCelsiusconverter,thentheprogrammerselectsuserinterfaceobjectsappropriatetothetaskanddisysthemonscreen.Inthisexample,theprogrammermightlettheuserenteratemperatureinaneditabletextarea,disytheconvertedtemperatureinanotherun-editabletextarea,andlettheuserexittheprogrambyclickingonapush-buttonlabeledAstheusermanipulatestheapplication'scontrols,theprogrammustrespondappropriay.Theresponsesaredeterminedbytheuser'sactionsonthedifferentcontrolsusingthemouseandthekeyboard.Eachuserinterfaceobjectonthescreenwillrespondtoeventsdifferently.Forexample,iftheuserclickstheQuitbutton,thebuttonmustupdatethescreenappropriay,highlightingitselfasnecessary.Thentheprogrammustrespondbyquitting.Normallythebuttonmanagesitsappearanceitself,andtheprograminsomewayreceivesamessagefromthebuttonthatsays,"Thequitbuttonwaspressed.Dosomethingaboutit."Theprogramrespondsbyexiting.Windowsfollowsthissamegeneralpattern.Inatypicalapplicationyouwillcreateamainwindowandceinsideitdifferentuserinterfacecontrols.Thesecontrolsareoftenreferredtoaschildwindows-eachcontrolislikeasmallerandmorespecializedsub-windowinsidethemainapplicationwindow.Astheapplicationprogrammer,youmanipulatethecontrolsbysendingmessagesviafunctioncalls,andtheyrespondtouseractionsbysendingmessagesbacktoyourcode.Ifyouhaveneverdoneany"event-driven"programming,thenallofthismayforeigntoyou.However,theevent-drivenstyleofprogrammingiseasytounderstand.Theexactdetailsdependonthesystemandthelevelatwhichyouareinterfacingwithit,butthebasicconceptsaresimilar.Inanevent-driveninterface,theapplicationpaintsseveral(ormany)userinterfaceobjectssuchasbuttons,textareas,andsontothescreen.Nowtheapplicationwaits-typicallyinapieceofcodecalledaneventloop-fortheusertodosomething.Theusercandoanythingtoanyoftheobjectsonscreenusingeitherthemouseorthekeyboard.Theusermightclickoneofthebuttons,forexample.Themouseclickiscalledanevent.Eventdrivensystemsdefineeventsforuseractionssuchasmouseclicksandkeystrokes,aswellasforsystemactivitiessuchasscreenAtthelowestlevelof ion,youhavetorespondtoeacheventinafairamountofdetail.ThisisthecasewhenyouarewritingnormalCcodedirectlytotheAPI.Insuchascenario,youreceivethemouse-clickeventinsomesortofstructure.Codeinyoureventlooplooksatdifferentfieldsinthestructure,determineswhichuserinterfaceobjectwasaffected,perhapshighlightstheobjectinsomewaytogivetheuservisualfeedback,andthenperformstheappropriateactionforthatobjectandevent.Whentherearemanyobjectsonthescreentheapplication esverylarge.Itcantakequiteabitofcodesimplytofigureoutwhichobjectwasclickedandwhattodoaboutit.Fortunay,youcanworkatamuchhigherlevelof ion.InMFC,almostalltheselow-levelimplementationdetailsarehandledforyou.Ifyouwanttoceauserinterfaceobjectonthescreen,youcreateitwithtwolinesofcode.Iftheuserclicksonabutton,thebuttondoeseverythingneededtoupdateitsappearanceonthescreenandthencallsapre-arrangedfunctioninyourprogram.Thisfunctioncontainsthecodethatimplementstheappropriateactionforthebutton.MFChandlesallthedetailsforyou:Youcreatethebuttonandlitaboutaspecifichandlerfunction,anditcallsyourfunctionwhentheuserpressesit.Tutorial4showsyouhowtohandleeventsusingmessagemaps.Thestepsnecessarytoenterandcompilethisprogramarestraightforward.IfyouhavenotyetinstalledVisualC++onyourmachine,dosonow.Youwillhavetheoptionofcreatingstandardandcustominstallations.Forthepurposesofthesetutorialsastandardinstallationissuitableandafteransweringtwoorthreesimplequestionstherestoftheinstallationisquickandpainless.MFC简要介VisualC++C++Windows应用程序。为了能充分利用这些特性,你必须理解C++C++,你就必须掌握基本类库(MFC)的层次结构。该层次结构包容了WindowsAPI中的用户界面部分,并使你能够很容易地以面向对象的方式建立WindowsWindows用MFC所建立的代码是完全可移植的。这篇文章将向你介绍MFC的基本概念和术语以及驱动程序设计方法。MFC程序。下
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 现代化高楼大厦中的先进技术及其对行业的影响研究
- 科技赋能下的心理健康教育与职业培训深度融合研究
- 直播带货在电商营销中的兴起与发展
- 疫情后的新机遇中医药文化的教育推广策略
- 电子烟产业链结构与关键环节剖析
- 2025年护理安全管理工作计划
- 公共安全领域精神文明建设措施
- 2024-2025学年度二年级班主任家长会计划
- 2025年大米供应商合同模板
- 2025年交通事故责任认定与协议操作指南
- 2025年黑龙江职业学院单招职业适应性测试题库必考题
- 专利共有合同范例
- 《ABO血型鉴定》课件
- 苏教版五年级下册数学计算题大全1200道带答案
- 计算机行业人工智能系列深度报告:deepseek研究框架-国海证券-20250214
- 2025年山西省国有资本运营有限公司招聘笔试参考题库含答案解析
- 2025年湖南生物机电职业技术学院高职单招职业适应性测试近5年常考版参考题库含答案解析
- DB1331T 102-2025雄安新区应急物资储备库建设规范
- 北京市丰台区2024-2025学年九年级上学期期末道德与法治试题(含答案)
- 医院培训课件:《PET-CT的临床应用》
- 《莫比乌斯环》课件
评论
0/150
提交评论