Understanding the concept of "resource" in MFC

Source: Internet
Author: User

 

Visual c ++ supports ten types of resources: acceleration key, bitmap, cursor, dialog box, HTML, icon, menu, string table, toolbar, and version information.

Various resources are just heap data and will be embedded into the data zone in the EXE file. When necessary, it is loaded into the memory through the function. It is the same as a database. Each resource is uniquely identified by ID, just as the database uses keywords. Different resources can use equivalent IDs for different types, just as the keyword values in each form in the database are not unique, but the keywords in different forms are allowed to be the same.
Resource destruction means that resources should be released from the memory in a timely manner according to their use cycle. Do not load the resources into the memory and then ignore it. Otherwise, the larger the memory is.

You can create any required resources at any time. You only need to display resourceview, right-click the resources folder, and select insert from the context menu ). You will see an insert resource dialog box, as shown in. Note that it shows all the ten types of resources we have mentioned. You can also see that there are three ways to create resources: use the new, import, or custom buttons in the dialog box. Resources from other projects can be used in the current program. For example, you may want to use the same company logo in every program you write. Right-click the resources folder and select import from the context menu instead of insert ). You will see the open-type dialog box. Select the file containing the resource to be imported. For this reason, you may think of separating most of your resources from programs. Unfortunately, this method is only useful for icons, cursors, sonic files, and Visual Basic Form files. There are several ways to use other types of resources from other projects, such as the about (about) dialog box. Simply create a separate RC file for the resource you want to share. This is useful when encountering resources such as the about dialog box. You only need to add the RC file to the project, and the rest is processed by Visual C. Another way to share a resource is to copy it to the clipboard, and then paste it into the project after creating a correct type of blank Resource. Custom resources are self-designed resources. In fact, it is not suitable for the predefined types provided by Visual C. It is easy to create a custom Resource Project: Just click the insert M (custom) button in the insert resource dialog box. The new custom resource dialog box contains a single blank space. Enter a Custom Resource Name. In this case, Visual C will generate a new folder containing your custom Resource Name and a new resource in the folder. It also provides binary data required to implement this resource.

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.