《学习笔记3.docx》由会员分享,可在线阅读,更多相关《学习笔记3.docx(22页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、精品名师归纳总结资料word 精心总结归纳 - - - - - - - - - - - -学习好资料欢迎下载孙鑫 vc+学习笔记( Sun Xin vc+ learning notes)1. about creating window applicationsUnderstand the capabilities of the windows program, the API function, the relationship between the message queue and the operating system, the input and output devicesWin
2、dow programming, sub background and front deskFront desk for what kind of window, how to display the title, and the destruction of the window, the day after tomorrow continue to runBackground is the design purpose, he is through the window message queue continuous access to messages GetMessage and t
3、ranslation, that is, the winprocess function of the subfunctiontocallcallbackfunctiontoachieve,writtenby the user himselfMessages are implemented through applications that providefunctionstothe system platformtotunetheeffectsof hardware, sound, orimages.Applicationsare builton applicationsystemsThe
4、concrete steps are as followsThe construction of new Win32 Application source program written in empty project file with C program source file that contains the windows.h file to the WinMain function to writeitcontainsthemain functionofthisprogram withthefunction of DOS under the same entrance when
5、the application ends its WinMain function at the end is called by the operating system可编辑资料 - - - 欢迎下载精品名师归纳总结学习资料 名师精选 - - - - - - - - - -第 1 页,共 11 页 - - - - - - - - - -可编辑资料 - - - 欢迎下载精品名师归纳总结资料word 精心总结归纳 - - - - - - - - - - - -学习好资料欢迎下载allocates space assignmentThe program designincludes:thedef
6、initionofWinMain function to create a window to create a message loop write windowprocedure four step window: design a window class fill in the blank window display status includes cursor display background loading icon loadicon window function lpfnWndProc messageresponse functionby itsownoperatings
7、ystem,but need towrite code to call registered window class Registerclass to createa window createWindow window size coordinate menu handle and update updateWindow ShowWindow display window of eachfunctiontypeoperatingsystem isbasicallyfixedagaintoset a messageloopwhileGetMessage correspondingtothem
8、essage size and member variables the corresponding applicationmessage queue to achieve continuous operation program background TranslateMessage converted to wchar The distribution dispatchmessage to the middle layer of the callback function for operating system the last messageeditingwindow function
9、switchprocesstodealwiththemouse button to destroy the window and the end of the news programplusdefaultprompt:thesystem isthroughthewindow functionaddress pointer to invoke the process window function 2, about c+C+ has more advantages over C, mainly in encapsulation, inheritance and polymorphismSele
10、ct new project Win32 console application c+ source filewritteninstructurec+ body can writefunctionofforeignbody and thestructurecan callthemembervariablec+ functionin可编辑资料 - - - 欢迎下载精品名师归纳总结学习资料 名师精选 - - - - - - - - - -第 2 页,共 11 页 - - - - - - - - - -可编辑资料 - - - 欢迎下载精品名师归纳总结资料word 精心总结归纳 - - - - - -
11、 - - - - - -学习好资料欢迎下载similarbutby defaulttothemembervariableaccessisnotthe sameAn instance of a class and object instantiated with an object that defines a structure variable is to produce an objectConstructor: the important function is to create the object itself, and each object must have a constr
12、uctor that has the same form as the class name and has no return value,In a statement object will automatically call the default constructor is a constructor with no parameters are only responsible for creating object not initialized if the definition of a parameter or a zeroary constructor, c+ will
13、 not create a default constructorDestructor:theobjectisresponsibleforretrievingitsmemory space at the end of the objects life. In contrast to theconstructor, the arguments and return values are not allowed,and a class can only have one destructor.Overloading of functions: if the constructor overload
14、s, c+ automaticallymatches the calltothecorrespondingfunction, overloading the condition: the parameter type of the functionand the number of argumentsThis pointer: an implicit pointer to an object corresponding to itself, representing the address of the object this=&pt.Thismakes it easy towritethem
15、embervariablesintheobjectusing VCs automatic listing of member functions, using this 可编辑资料 - - - 欢迎下载精品名师归纳总结学习资料 名师精选 - - - - - - - - - -第 3 页,共 11 页 - - - - - - - - - -可编辑资料 - - - 欢迎下载精品名师归纳总结资料word 精心总结归纳 - - - - - - - - - - - -学习好资料欢迎下载Base classinheritanceand access characteristicsofthethree ki
16、ndsofsubclassestoinheritfathertosee thedefinitionof property inheritance characteristics and the parent class memberfunctiondecision,protectedinsubclassingbutoutside such as fish.breath main in the function cannot be calledby the fish class but can not be inherited visit the subclass inheritance, if
17、 the parent class with parameters, the subclass inheritance should also add parameters, the constructor callthe parent class and subclass, and the destructor calls in reverse orderOverlayoffunctions:a membervariablethatoccursbetween the two classes of a parent class and a subclass. The name of thefu
18、nctionisconsistent.Scope identifier:used toindicate which class of member variables the function belongs to andprevents the coverage of the member functions of the parent classPolymorphism: virtual in the base class member function, sub class inheritance, VC sub class visit, sub class has a member f
19、unction with the same name is called sub classes, subclassesdidnotcalltheparentclass.Another:purevirtualfunctions appear inbase classes,butareimplementedby derivedclassesReference and pointer: int a=5; int &b=a; a, B, point to thesamememoryspace atthesametime,AB isan aliaspointer,and the variable it
20、self occupies memory, which stores the contentas the address pointing to the variableFor write method of.Cpp file and.H file, create different files可编辑资料 - - - 欢迎下载精品名师归纳总结学习资料 名师精选 - - - - - - - - - -第 4 页,共 11 页 - - - - - - - - - -可编辑资料 - - - 欢迎下载精品名师归纳总结资料word 精心总结归纳 - - - - - - - - - - - -学习好资料欢
21、迎下载in the open the project can also be found in the project file new text file later renamed F2, VC function keys to add one to write different engineering documentsVC program to compile and link mechanism: precompiled , and when the project file is established to find the solutionto the project fil
22、e, header file contains repeated problems:#ifdef XX #define XX preparation after adding ENDIF, repeat this definition can prevent the error, prevent the VC compilation process mechanism integration: the pre processorto the pre compiled instruction compiler # to project source code .Cpp separately co
23、mpiled machine instructions contains different object file debag.Obj file, and finally by theconnector to the target file .Obj and c+ standard library function standard library .Lib to generate a the executablefile.Exe.Tip:compiletimetotroubleshoot.Cppsourcefilesindividually.3 MFC programmingAn obje
24、ct oriented library of functions is provided to users in a class mannerMFC AppWizard is used tocreate asingledocument based on the MFC interface SDI applications, the new MFC AppWizardgeneration program dialog box click OK can see the operationoftheprogram,on the leftside ofVCworkspace classviewtag
25、can be seen in the five class of the automatically generated,only need to turn on the following class you can write codeFirstofall,tounderstandtheinternalmechanism ofMFC,you可编辑资料 - - - 欢迎下载精品名师归纳总结学习资料 名师精选 - - - - - - - - - -第 5 页,共 11 页 - - - - - - - - - -可编辑资料 - - - 欢迎下载精品名师归纳总结资料word 精心总结归纳 - -
26、- - - - - - - - - -学习好资料欢迎下载can find that the WinMain function is not found in findfile,but search theWinMain function not the file intheMFC file SRCfilethesourcecode ofMFCintheinstallationdirectory Under thecare,fiveclasseswhere CMainFrameisa fixedname, which isderivedfrom CFrameWnadnd CWndderivedf
27、rom thewindow classishowtocombine withWinMain. hint:foralltheglobal variables in global, the global object global variables areassigned to memory before WinMain you can search the cwinapp, initialization function view defines its constructor goodwindow tab to switch VC,An example application is told
28、 by the instance handle parameter hinstance WinMain function to mark, and for MFCapplications through theobject applicationclass touniquelyidentify the application examples of each MFCprogram and only a copy of the application class CwinApp derived class, every MFC there is only one instance of the
29、derived classinstantiation of objects, theApp is the global object, theobjectthattheapplicationitself,beforethetheApp CTestApp object constructorcallwill callthesuperclassconstructor, and from associating our own program to create the class andMicrosoft provides the base class. The CWinApp construct
30、orcompletessomeinitializationwhen theprogram isrunning.The lookup cwinapp will find that it is a constructor with aparameter,and we do notpass arguments tothe baseclass when we inherit,because cwinapp istheconstructorwiththedefault value.When the program calls the constructor of the cwinapp class, a
31、nd the implementation of the ctestapp class constructor, andproduceda theappobject,thenentertheWinMain function,the可编辑资料 - - - 欢迎下载精品名师归纳总结学习资料 名师精选 - - - - - - - - - -第 6 页,共 11 页 - - - - - - - - - -可编辑资料 - - - 欢迎下载精品名师归纳总结资料word 精心总结归纳 - - - - - - - - - - - -学习好资料欢迎下载WinMain function is actually c
32、an be found by calling the afxwinmain function to complete the function AFX for the application frame functionInaccordancewiththeproceduresforthepreparationofWin32 steps to design the window class and register window classshould create the window window created in MFC function isrealizedby createxCW
33、ndfunctionsofthefunctiondeclaration in the afxwin.h fileCframe istheoperationofthewindow functionismarked CView window when the program is running the following blank window precreatwindow using virtual function polymorphism allows programmers to modify the appearance of the window in thesubclass it
34、 extended function in creatwindow before the execution of MFC suffix function called ex isMFC window class internal operation summary:1,first,you starttheapplicationwiththeglobalapplication objecttheapp,which istheglobalobject,and thethispointer inthebase classcwinapp can pointtotheobject.Withoutthi
35、s globalobject,theprogram does notmakeerrorsatcompiletime,But there will be errors at runtime2 call the global application object constructor, which will be the base class constructor cwinapp electrophoresis, the latter performs some initialization application, and the application of object pointers
36、 stored可编辑资料 - - - 欢迎下载精品名师归纳总结学习资料 名师精选 - - - - - - - - - -第 7 页,共 11 页 - - - - - - - - - -可编辑资料 - - - 欢迎下载精品名师归纳总结资料word 精心总结归纳 - - - - - - - - - - - -学习好资料欢迎下载3 enter the WinMain function, in the afxwinmain function. In the afxwinmain function can obtain the subclass for test applications, is the
37、 ctestapp class pointer, the pointer by calling a virtual function: InitInstance function, whichperformssomeinitializationapplication,includingthewindow class is registered, create, display and update. The createxfunctioniscalledmultipletimesbecause a singledocument MFC applicationhas multiple windo
38、ws,includingthe framewindow, toolbar, status bar, and so on4 entering the message loop, although the default processfunctionisset,theMFCapplicationuses a messaging mechanism to process various messages, and when you receive the wm_QUIT message, exit the message loop and end the programThe cdocument
39、classisa document classthatisnotderivedfrom the CWnd class, so it is not a window class. MFC provides adocument /viewarchitecture,includingdocument referstothe cdocument class, as is CView, data storage and loading is accomplished by a document type, display and modify the datatobe completedby thevi
40、sualcategory,thusthedata management and display method of separationThe caboutdlg class is derived from the CDialog class, which is born in CWnd, so it is the window class, which primarily provides program related help information, such as version numbersTip:inthedefinitionsofthememberfunctionsthems
41、elves,if the call API provided by window function and their functionisdifferent,so theAPI functionnamecan notbe added: symbols,可编辑资料 - - - 欢迎下载精品名师归纳总结学习资料 名师精选 - - - - - - - - - -第 8 页,共 11 页 - - - - - - - - - -可编辑资料 - - - 欢迎下载精品名师归纳总结资料word 精心总结归纳 - - - - - - - - - - - -学习好资料欢迎下载thecompilerautomat
42、icallyidentifiestheAPI function,butif the API function member function and internal call currentlydefinedisthesameas thatofthe latterthefrontmust be added: symbols,otherwisetheprogram willfailatruntimeorcompileUse the source code to write a button control, pay attentionto add to the corresponding cl
43、ass become the private member variables, and the corresponding function create createdisplaycontrolcode writteninvc+,as a kindofadd a messageprocessing function method is: in the classview tab, right click on the the class name, select the add window messagehandler. menu command from the shortcut me
44、nu pop-up, thenpop-up selectiondialogbox,selectthekey positiontoadd the wm_create control message. See this pointer to the class,rather than the source positionThis chapter finds that many window class function calls no longer need to pass window handles because they all maintain a window handle member variable internally4. simple drawingAnalyze the MFC message mapping mechanism, design a drawing program to understand messaging and captureAfter analysis, a MFC message response function has three relevant information in the program: the function prototype, the function i