学习笔记3.docx
精品名师归纳总结资料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 devicesWindow 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 translation, 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 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 the application ends its WinMain function at the end is called by the operating system可编辑资料 - - - 欢迎下载精品名师归纳总结学习资料 名师精选 - - - - - - - - - -第 1 页,共 11 页 - - - - - - - - - -可编辑资料 - - - 欢迎下载精品名师归纳总结资料word 精心总结归纳 - - - - - - - - - - - -学习好资料欢迎下载allocates space assignmentThe program designincludes:thedefinitionofWinMain 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 itsownoperatingsystem,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 correspondingtothemessage 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 functionswitchprocesstodealwiththemouse 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 polymorphismSelect new project Win32 console application c+ source filewritteninstructurec+ body can writefunctionofforeignbody and thestructurecan callthemembervariablec+ functionin可编辑资料 - - - 欢迎下载精品名师归纳总结学习资料 名师精选 - - - - - - - - - -第 2 页,共 11 页 - - - - - - - - - -可编辑资料 - - - 欢迎下载精品名师归纳总结资料word 精心总结归纳 - - - - - - - - - - - -学习好资料欢迎下载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 constructor 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 not create a default constructorDestructor:theobjectisresponsibleforretrievingitsmemory space at the end of the object's 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 overloads, 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 towritethemembervariablesintheobjectusing VC's automatic listing of member functions, using this >可编辑资料 - - - 欢迎下载精品名师归纳总结学习资料 名师精选 - - - - - - - - - -第 3 页,共 11 页 - - - - - - - - - -可编辑资料 - - - 欢迎下载精品名师归纳总结资料word 精心总结归纳 - - - - - - - - - - - -学习好资料欢迎下载Base classinheritanceand access characteristicsofthethree kindsofsubclassestoinheritfathertosee 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 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 thefunctionisconsistent.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 function 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 itself 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 精心总结归纳 - - - - - - - - - - - -学习好资料欢迎下载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 file, 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 compiled 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 object 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 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 精心总结归纳 - - - - - - - - - - - -学习好资料欢迎下载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 CWndderivedfrom 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 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 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 constructorcompletessomeinitializationwhen 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, and the implementation of the ctestapp class constructor, andproduceda theappobject,thenentertheWinMain function,the可编辑资料 - - - 欢迎下载精品名师归纳总结学习资料 名师精选 - - - - - - - - - -第 6 页,共 11 页 - - - - - - - - - -可编辑资料 - - - 欢迎下载精品名师归纳总结资料word 精心总结归纳 - - - - - - - - - - - -学习好资料欢迎下载WinMain function is actually can 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 createxCWndfunctionsofthefunctiondeclaration 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 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.Withoutthis 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 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 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 windows,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 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 thevisualcategory,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:inthedefinitionsofthememberfunctionsthemselves,if the call API provided by window function and their functionisdifferent,so theAPI functionnamecan notbe added: symbols,可编辑资料 - - - 欢迎下载精品名师归纳总结学习资料 名师精选 - - - - - - - - - -第 8 页,共 11 页 - - - - - - - - - -可编辑资料 - - - 欢迎下载精品名师归纳总结资料word 精心总结归纳 - - - - - - - - - - - -学习好资料欢迎下载thecompilerautomaticallyidentifiestheAPI 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 class 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 menu 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