VC ++ Summary

Source: Internet
Author: User

1. A non-0 value indicates true, and a 0 value indicates false );

2. STL and MFC

C ++ is a language and has limited functions. It requires some class libraries to encapsulate common operations and can be called directly in the future, saving a lot of effort. STL and MFC are both class libraries that expand C ++ functions.

STL is the underlying class library. It provides the functions used in general programming, mainly a set of containers and a set of related algorithms. common data structures, such as list, queue, stack, and map, are all implemented in STL and can be used directly.

MFC is a high-level Library (relative to STL). It encapsulates WIN32API functions and encapsulates thousands of complex API functions, it also facilitates the development of Native Windows programs through its own unique message processing system. compared with STL, MFC is used only when developing Native Windows programs.

3. capture key messages in the dialog box

(1) You can reload the virtual function pretranslatemessage in the dialog box class (I personally think it is better, of course, the application class can also be reloaded );

(2) Reload the virtual function processmessagefilter in the application class (for more information about implementation, see chapter 4 of Sun Xin, and add code in the dialog box class. The benefits are to be verified );

4. If you want to limit a value to a certain range, the best way is to perform a modulo operation, for example, Index = ++ index % 3;

5. Custom messages

(1) Use wm_user to prevent conflicts between the custom message ID and the system Message ID. If the value is smaller than the value of wm_user, it can be used by users, for example, # define um_progress wm_user + 1 (cannot exceed 0x7ffff );

(2) The prototype afx_msg lresult onprogress (wparam, lparam) of the message response function is declared that void cannot be used, and parameters must be included whether required or not;

(3) Use the on_message macro, such as on_messsage (um_porgress, cmainframe: onprogress). cmainframe is the class name of the class where it is located. Here it is the framework class;

(4) when defining a function in the CPP file, you can return any value, for example, return true;

(5) sendmessage (MSG) is used to send messages. The message will be returned only after the MSG message is executed;

(6) postmessage (MSG) is used to send a message to the message queue and then return immediately. The MDG message is executed only after the execution of the message is complete;

6. Resource. H and. RC file --- the custom menu, dialog box, and other resources are all in. in the RC file, and the resource ID is declared in the resource. h can be considered. one of the RC header files;

7. Narrow characters and wide characters-for the nominal value such as "AA", you can use L or _ t for conversion, and the variable uses the header file atlconv. for a2w or w2a under H, you need to write a uses_conversion macro before using the code (do not write the macro inside the circular function );

8. The writing and reading methods of files must be consistent. It is best to use the binary mode for reading and writing files. When writing data in text mode, if a newline character (with an ASCII Code of 10) is encountered, it is converted to a newline character (with an ASCII Code of 13 and 10). The opposite is true for reading and writing files, if the file is written in binary mode, the output is as is. After the file is written in 10, the notepad becomes a small black dot. The line break is displayed when the file is read in text mode;

9. ASCII code Display conversion-when opening a file in text mode, each byte in the file will be converted to the corresponding ASCII character display,Each byte is displayed in hexadecimal format after opening a file in binary format in ,,61 33 34 31 on the left is the hexadecimal display of a341 on the right. Each number represents one byte:

10. File Dialog Box class --- file filter format: "text files (*. TXT) \ 0 *. TXT "is an item, each item is separated by \ 0, and two \ 0 are added at the end of the last filter;

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.