Windows programming FAQ

Source: Internet
Author: User
Tags textout

1 Q: What is the connection and difference between the basic part of C ++ and the subsequent windows programming design ideas?
A:
(1)The basic programming idea of C ++ language is console-based (DOS) programming, rather than the true scope of Windows programming design;
Reason:)The basic part of the C ++ language is output on the Character interface.(Printf, cout <); andWindows program output is graphic interface;
B)The basic program of C ++ language is based on process execution.AndWindows programs are event-driven;
C) the input of the basic part of the C ++ language generally accepts the keyboard character input directly. The input of the Windows program mainly includes the mouse, keyboard, and timer;
(2) c ++ language learning is the foundation of Windows Programming Design (the foundation of MFC programming)
Reason: a) C ++ is an object-oriented programming language (OOP ).Encapsulation, inheritance, and PolymorphismFeatures are conducive to collaborative development of Windows programs, saving development and maintenance costs;
(3) The programming idea of the basic part of C ++ focuses on the C ++ language itself. The programming idea of Windows programming design focuses on the basic mechanism of windows and the learning of MFC.

2 Q: What are the basic requirements of the C ++ language? What are the basic requirements for Windows Programming in the last eight sections?
A:
(1) The programming logic of the basic part of C ++ focuses on the C ++ language itself:
Basic requirements:
A) understand basic features of OOP and be familiar with basic language phenomena of C ++ language (abstraction, encapsulation, inheritance and derivation, polymorphism, and virtual functions)
B) The C ++ code written by others can be basically understood: class hierarchy, class member variables and member functions;
C) master the basic usage of the VC development platform;Learn Basic process-based debugging methods (breakpoint debugging, one-step tracking, watch, and callstack)
(2) Windows programming design focuses on the basic mechanism of windows and the learning of MFC:
Basic requirements:
A)Understand the basic mechanism of Windows programs (basic structure and message mechanism of Windows programs)
B) understand the MFC framework and MFC class levels;Master the features and usage of basic classes(Cwinapp; cwnd; cstring; CDC; cpoint; crect; cdocument; cview; carchive; cdialog; cedit; cbutton; clistbox; cControl)
C) In addition to the basic process-based debugging methods (for local debugging), the basic event-based debugging methods (SPY ++; trace; Assert) are supplemented and learned)
D)Master some key points: Document view (DOC/view) structure; dialog box and use of various controls;

3. SDKProgramming and MFC programming?
A:
(1) SDKProgramming and MFC programmingAll are windows programming methods. MFC programming is the development of SDK programming methods.
SDK programming is a traditionalWin32API underlying development, time-and labor-consuming programming methods;
MFC programming is a modular, time-and labor-saving programming method developed on the basis of the MFC class.
(2) SDK programming is quick and easy to understand; it is difficult to get started with MFC programming and the learning process is long (generally it takes six months to one year to get started first );
SDK programming can be analogous to "Analog Circuit Design" in electronics; MFC programming can be analogous to "Digital Circuit Design" in electronics ";

4. What are the learning points of MFC programming?
A: MFC programming is an object-oriented programming idea (OOP). The focus is to use the objects (classes) that have been built by the predecessors to derive their own new objects and assign new features, to complete our Windows applications with unique features.
The learning points of MFC are as follows:
A) refer to the typical examples to learn more about Windows message mechanism and MFC program framework through reading and imitating them;
B) gradually accumulate methods for using MFC classes and member functions;
C) cultivate good programming habits, Master Basic Debugging techniques and skills, and develop the habit of online data access;

5 Q: Generally, the Code on vc6.0 contains the ondraw function. Why can't I find the ondraw function in the helloworld program in the class?
A: In order to step by step, the DOC/view structure is removed from the MFC framework created in the lesson. Therefore, the generated cchildview class is derived not from cview, but from the basic class cwnd.
Please pay attention to the onpaint message response function of the cwnd class.
Onpaint is similar to ondraw, but onpaint is simpler and suitable for beginners.

6. Can I explain the relationship between ondraw and onpaint in advance?
A: ondraw is a member function of cview (virtual function, not a message response function). It outputs (including screen output and print output) in the View/document structure) encapsulation;
Onpaint is the message response function of the window class cwnd.

Because cview is a derived class of window class cwnd, The wm_paint message response function of cview is also onpaint.
In the cview and cview Derived classes, the relationship between ondraw and onpaint is: (1) ondraw is called in the onpaint function; (2) When cview and derived classes are used, generally, you only need to process the ondraw code, while onpaint is typically encapsulated.

7. Where should the data variables be defined when the SDK job (sine animation) is transformed to the MFC program?
A: This problem should have been solved in C ++ language learning. Here we will summarize it.
In MFC programming (C ++ programming), there are three methods to define data variables.
A)If the Defined variables only need to be used in a specific CPP file, they can be directly defined at the top of the CPP file. Generally, they are defined as static variables). Once defined, all class member functions or global functions in the CPP file can access and use these variables. For this usage, see the indicators static variable in mainfrm. cpp.(This method is used in the drawing demo program drawdemo)
B)Define public or static member variables in some classes and use them globally.. For this usage, refer to the member variable m_wndview of cmainframe in mainfrm. h and the usage of m_wndview in mainfrm. cpp.
C) if the variables to be defined are used in multiple CPP files, we recommend that you construct a structure or class, encapsulate these variables, and then access them. In this case, you need to construct an object in the CPP file and include the Class header file to the CPP file. For this usage, refer to theapp in the program framework.
Of course, you can also (not recommended) refer to the relevant use methods in C Programming, define in a CPP file, and in the public header file (. h), and include it to the CPP file that needs to access and use these variables.


8 Q: When I transform an SDK job (sine animation) to an MFC program, which class should I add the message response function of the menu command? Chelloworldapp, cmainframe, or cchildview?
A: Actually,It is feasible to add a message response function to the above three classes.. Consider the most convenient Implementation Scheme. The specific situation needs to be analyzed.
(1) If the variable definition adopts the same definition method as drawdemo (the first method above), it should be added to the cchildview class. In this way, all variables are used in the same CPP file, making code writing and maintenance the most convenient.
(2) If the variable definition adopts the second method, that is, defining it as a member variable of a class, it is feasible to add the menu command message response function to any class. In this case, the scope operator of the class must be used for specific programming ::.
By the way, after learning the DOC/view document structure, most of the variable data will be encapsulated in the document class (the second method is the variable definition method ); especially after learning the multi-document (MDI), you need to analyze the impact scope of the menu command, and then decide the class in which to respond to the Command Message.

9 Q: When I transform the SDK job (sine animation) to the MFC program, according to The helloworld demonstration in the lesson, my program framework also does not use the DOC/view structure. When I used classwizard to add the wm_timer message ing function to the cchildview class, I found that there was no wm_timer message in the message (messages) to be selected on the right, even wm_paint. Why?
A: On the class info page in classwizard, select the cchildview class and change the message filter from "not a window" to "window ". Then, all WM _... standard messages can be mapped.
This generated application framework is a little inconvenient: (you should set the message filter to "window" by default.


10 Q: What is the relationship between the device description table CDC and various GDI objects (cpen, cbrush, etc?
A: For example:
CDC is a canvas, and various GDI objects are tools in the hands of painters;
The entire process of PaintingAnalogy with painter painting:
(1) Preparations(: Beginpaint ());
(2) painter adjustment tools(CDC: SelectObject (...)),
Pigment Selection(CDC: settextcolor (...); CDC: setbkcolor (...)),
Follow certain techniques(CDC: setrop2 (...)),
Draw several strokes on the canvas(CDC: textout (...), CDC: ellipse (...) and other member functions);
(3) painter adjustment tools(CDC: SelectObject (...)),
Pigment Selection(CDC: settextcolor (...); CDC: setbkcolor (...)),
Follow certain techniques(CDC: setrop2 (...)),
I drew several more pens on the canvas.(CDC: textout (...), CDC: ellipse (...) and other member functions);
(...)...
(N) until all work is completed successfully(: Endpaint ()).


11 Q: What are the learning points of the document view structure?
A ::
Document/view structure is an important concept of the MFC application framework.
Key points:
(1) Relationship between views and documents, coordination programming between views and documents;
(2) serialization of the document [one application is file input/output (IO )];
(3) master the usage and usage of various typical view and document classes. [accumulate during use]
Other highlights:
(1) The MFC Application Framework coordinates the framework window, document, and view mechanisms (Document Template cdoctemplate and Document Manager cdocmanager ).
(2) Dynamic Object and type check.


(3) SDK Programming Win32Basically, the corresponding member functions can be found in the MFC class. Win32The API function has one less parameter (the handle of the operation object );
(* 4) advanced usage skills (generally not recommended ): Win32API functions can also be used directly during MFC programming. Use the global scope operator" ::", And the object handle can be called. For example: : Sleep (50); Or : Flashwindow (cwnd: getsafehwnd (), true)
(5) In short, learning the SDK is conducive to deepening the understanding of the Windows program running mechanism and helping to learn the MFC; the fundamental objective of learning MFC is to improve programming efficiency and program stability, and reduce program development and maintenance costs;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.