学习笔记(SunXinvclearningnotes)_第1页
学习笔记(SunXinvclearningnotes)_第2页
学习笔记(SunXinvclearningnotes)_第3页
学习笔记(SunXinvclearningnotes)_第4页
学习笔记(SunXinvclearningnotes)_第5页
已阅读5页,还剩5页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、学习好资料欢迎下载孙鑫 vc+学习笔记(Sun Xin vc+ learning notes)1. about creating window applicationsUn dersta nd the capabilities of the win dows program, the API fun cti on, the relati on ship betwee n the message queue and the operati ng system, the in put and output devicesWin dow program ming, sub backgro und a

2、nd front deskFront desk for what kind of window, how to display the title, and the destructi on of the win dow, the day after tomorrow continue to runBackground is the design purpose, he is through the window message queue con ti nu ous access to messages (GetMessage and tran slati on), that is, the

3、 win process fun cti on of the sub function to call (callback function) to achieve, written by the user himselfMessages are impleme nted through applicati ons that provide fun cti ons to the system platform to tune the effects of hardware, sound, or images. Applicationsare built on application syste

4、msThe con crete steps are as followsThe con structi on of new Win32 Applicati on source program written in empty project file with C program source file that contains the windows.h file to the WinMain function to write it contains the main function of this program with the function of DOS under the

5、same entrance when the application ends its WinMain function at the end is called by the operating systemallocates space assig nmentThe program desig n in eludes: the defi niti on of WinM ai n fun cti on to create a win dow to create a message loop write win dow procedure four step window: design a

6、window class (fill in the blank window display status includes cursor display background load ing icon loadic on win dow fun cti on IpfnWn dProc message response function by its ownoperating system, but need to write code to call) registered wi ndow class Registerclass to create a wi ndow (createWi

7、ndow wi ndow size coord in ate menu han dle and update updateWi ndow ShowWi ndow) display win dow of each function type operating system is basically fixed again to set a messageloop while (GetMessage (corresponding to the message size and member variables) the corresp onding applicatio n message qu

8、eue) to achieve con ti nu ous operati on program (backgro und) Tran slateMessage (conv erted to wchar) The distributio n (dispatchmessage to the middle layer of the callback fun cti on for operat ing system) the last messageediting window function switch (process to deal with the mouse butt on to de

9、stroy the wi ndow and the end of the n ews program plus default) prompt: the system is through the window function address (poi nter) to inv oke the process wi ndow fun cti on2, about c+C+ has more adva ntages over C, mainly in en capsulatio n, in herita nee and polymorphismSelect new project Win32

10、con sole applicati on c+ source file written in structure c+ body can write function of foreign body and the structure can call the membervariable c+ function in similar but by default to the membervariable access is not the sameAn in sta nee of a class and object in sta ntiated with an object that

11、defines a structure variable is to produce an objectCon structor: the importa nt fun cti on is to create the object itself, and each object must have a constructor that has the same form as the class n ame and has no return value,In a statement object will automatically call the default con structor

12、 is a con structor with no parameters are on ly responsible for creating object not initialized if the definition of a parameter or a zeroary constructor, c+ will not create a default con structorDestructor: the object is responsible for retrievingits memoryspace at the end of the objects life. In c

13、ontrast to thecon structor, the argume nts and return values are not allowed, and a class can only have one destructor.Overloadi ng of fun cti ons: if the con structor overloads, c+ automatically matches the call to the corresponding function, overloadi ng the con diti on: the parameter type of the

14、fun cti on and the nu mber of argume ntsThis pointer: an implicit pointer to an object corresponding to itself, representing the address of the object (this=&pt).This makes it easy to write the membervariables in the object (using VCs automatic listing of member functions, using this )Base class inh

15、eritaneeand access characteristics of the threekinds of subclasses to inheritfather to see the definition ofproperty in herita nee characteristics and the pare nt class memberfunction decision, protected in subclassing but outside (such as fish.breath (main) in the function cannot be called by the f

16、ish class but can not be inherited) visit the subclass in herita nee, if the pare nt class with parameters, the subclass in herita nee should also add parameters, the con structor call the pare nt class and subclass, and the destructor calls in reverse orderOverlay of functions:a membervariable that

17、 occurs between thetwo classes of a pare nt class and a subclass. The n ame of the function is consistent. Scope identifier (:) used to indicate which class of member variables the function belongs to and preve nts the coverage of the member fun cti ons of the pare nt classPolymorphism: virtual in t

18、he base class member function, sub class in herita nee, VC sub class visit, sub class has a member fun cti on with the same n ame is called sub classes, subclasses did not call the pare nt class. Ano ther: pure virtualfun cti onsappear in base classes, but are implemented by derived classesReferenee

19、 and pointer: int a=5; int &b=a; a, B, point to the same memoryspace at the sametime, AB is an alias pointer, and the variable itself occupies memory, which stores the content as the address pointing to the variableFor write method of.Cpp file and.H file, create differentfiles in the open the projec

20、t can also be found in the project file new text file (later renamed F2, VC function keys) to add one to write differe nt engin eeri ng docume ntsVC program to compile and link mecha ni sm: precompiled , and when the project file is established to find the solution to the project file, header file c

21、ontains repeated problems: #ifdef XX #defi ne XX (preparatio n) after addi ng ENDIF, repeat this definition can prevent the error, prevent the VC compilati on process mecha nism in tegrati on: the pre processor to the pre compiled instructioncompiler (#) to project sourcecode (.Cpp) separately compi

22、led machine instructions contains differe nt object file (debag.Obj file), and fin ally by the connector to the target file (.Obj) and c+ standard library fun cti on sta ndard library (.Lib) to gen erate a the executable file (.Exe). Tip: compile time to troubleshoot.Cpp source files in dividually!3

23、 MFC program mingAn object orie nted library of fun cti ons is provided to users in a class mannerMFC AppWizard is used to create a single document based on the MFC in terface (SDI) applicatio ns, the new MFC AppWizard generation program dialog box click OK can see the operation of the program, on t

24、he left side of VCworkspace classview tag can be see n in the five class of the automatically gen erated, only n eed to tur n on the follow ing class you can write codeFirst of all, to understand the internalmechanism of MFC,youcan find that the WinMain function is not found in findfile, but search

25、the WinMain function (not the file) inthe MFC fileSRCfile (the source code of MFC)in the installationdirectoryUnder the care, five classes (where CMainFrameis a fixed name, which is derived from CFrameWnand CWncderived from the window class) is howto combine with WinMain. (hint:for all the globalvar

26、iables in global), the global object global variables are assig ned to memory before WinMain you can search the cwin app, initialization function view defines its constructor good(wi ndow tab to switch VC),An example applicati on is told by the in sta nee han dle (parameter hinstance WinMain functio

27、n) to mark, and for MFC applicati ons through theobject applicati onclass to uniq uelyidentify the applicationexamples of each MFCprogram and onlya copy of the application class (CwinApp) derived class, every MFC there is only one instance of the derived class instantiation of objects, theApp is the

28、 global object, the object that the application itself, before the theApp CTestApp object constructor call will call the superclass constructor, and from associati ng our own program to create the class and Microsoft provides the base class. The CWi nApp con structor completes someinitializationwhen

29、 the program is running. Thelookup cwinapp will find that it is a constructor with a parameter, and we do not pass arguments to the base class when we inherit,because cwinapp is the constructor with the defaultvalue.Whe n the program calls the con structor of the cwin app class, and the impleme ntat

30、io n of the ctestapp class con structor, and produced a theapp object, then enter the WinMain function,theWinMain function is actually can be found by calling the afxwi nmain fun cti on to complete the fun cti on (AFX for the applicati on frame fun cti on)In accordanee with the procedures for the pr

31、eparationof Win32steps to desig n the wi ndow class and register wi ndow classshould create the wi ndow wi ndow created in MFC fun cti on is realized by createx CWncfunctionsof the function declarationin the afxwin.h fileCframe is the operation of the window function is marked CView win dow whe n th

32、e program is running the follow ing bla nk win dow precreatw in dow (us ing virtual fun cti on polymorphism allows programmers to modify the appeara nee of the wi ndow in the subclass) it exte nded fun cti on in creatw in dow before the execution of MFC suffix function called ex isMFC wi ndow class

33、in ternal operati on summary:1, first, you start the applicationwith the global applicationobject theapp, which is the global object, and the this pointer in the base class ewinapp can point to the object. Without this global object, the program does not makeerrors at compile time,But there will be

34、errors at run time2 call the global application object constructor, which will be the base class con structor ewin app electrophoresis, the latter performs some initialization application, and the applicati on of object poin ters stored3 enter the WinMain function, in the afxwinmain function. In the

35、 afxwi nm ai n fun cti on can obtai n the subclass (for test applicati on s, is the ctestapp class poin ter, the poin ter) by calli ng a virtual fun cti on: Initln sta nee fun cti on, whichperforms some in itializati onapplicati on,in cludi ng the win dowclass is registered, create, display and upda

36、te. The createx function is called multiple times because a single document MFC application has multiple windows,includingthe frame window,toolbar, status bar, and so on4 en teri ng the message loop, although the default processfunction is set, the MFCapplicationuses a messaging mechanismto process

37、various messages, and whe n you receive the wm_QUIT message, exit the message loop and end the programThe cdocument class is a document class that is not derived from the CWnd class, so it is not a window class. MFC provides a document / view architecture,including document refers to thecdocume nt c

38、lass, as is CView, data storage and load ing is accomplished by a docume nt type, display and modify the data to be completed by the visual category, thus the data management and display method of separati onThe caboutdlg class is derived from the CDialog class, which is born in CWnd, so it is the w

39、indow class, which primarily provides program related help in formati on, such as vers ion nu mbersTip: in the definitions of the memberfunctions themselves, if the call API (provided by window) function and their function is different, so the API function namecan not be added: symbols,the compiler

40、automaticallyidentifiesthe API function, but ifthe API function member function and internal call currently defined is the sameas that of the latter the front must be added: symbols, otherwise the program will fail at run time or compileUse the source code to write a butt on con trol, pay atte nti o

41、n to add to the corresp onding class become the private member variables, and the corresp onding fun cti on create create display control code written in vc+, as a kind of add a message processing function method is: in the classview tab, right click on the the class name, select the add window mess

42、age han dler. menu comma nd from the shortcut menu pop-up, the n pop-up selection dialog box, select the key position to add the wm_create con trol message. See this poin ter to the class, rather tha n the source positi onThis chapter finds that many window class function calls no Ion ger n eed to p

43、ass win dow han dles because they all maintain a win dow han dle member variable intern ally4. simple draw ingAn alyze the MFC message mapp ing mecha ni sm, desig n a draw ing program to un dersta nd messagi ng and captureAfter an alysis, a MFC message resp onse fun cti on has three releva nt in for

44、matio n in the program: the fun cti on prototype, the fun cti on impleme ntatio n, and the macro used to correlate the message and the message resp onse fun cti on. The stateme nt in the header file that is the prototype of the messageresponse fun cti on betwee n the two AFX_MSG_n no tati on macros.

45、 There are two sources in the file: one is the message mapp ing macro between the two AFX_MSG_MAP ann otatio ns,Through this macro, the messageis associated with the message response function; the other is the implementation code of the message resp onse fun cti on in the source file.In the first chapter of the news cycle, when the message is gen erated, the operat ing system will put the message into the applicati on queue, took out a specific message through GetMessage fun cti on and di

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论