VI: Windows Application Development Interface Resources

Source: Internet
Author: User

Resources have an important role to play in application development. In particular, the interface elements (menus, icons, bitmaps, etc.) as resources, to reduce the workload of programming greatly help.

Resource Scripts (. Rc

Resources are in the resource script (. RC) is configured in the. For example, the Resource Name is window, and then the window is configured as follows,

1 Adding resources

By adding a resource window, you can add the required resources to the. rc file, such as commonly used dialog,bitmap,menu.

After adding the appropriate resources, the contents of the Window.rc file are as follows:

2 Drawing Resources

This does not need to write code, smart Visual Studio allows the use of "WYSIWYG" way to develop the interface of the resource, let's use "draw" to represent it. This step mainly uses the controls in the toolbox to "draw" out the various resources that are needed. You need to pay attention to the name of the resource ID, the names should be easy to remember and conform to certain rules, because this facilitates the development and maintenance of the program.




Resource ID definitions and header files

A resource ID is a unique identifier for a resource or resource subkey, and many resources and subkeys have identities. The importance of resource IDs has been mentioned above. such as Idd_dialog_about, id_file_copy, etc. is the resource ID. These IDs are actually user-defined constants that are defined in the auto-generated resource.h header file.

//{{no_dependencies}}//Microsoft Visual C + + generated include file.//used by windows.rc//#define IDD_DIALOG_ABOUT 101#define Idr_menu_main 101#define IDR_MENU_POPUP 102#define Idi_icon_main 103#define IDC_EDIT_ABOUT 1001#define ID_FILE_COPY 40001#define ID_FILE_SAVE40002 40002#define ID_FILE_EXIT 40003#define ID_EIDT_COPY 40004#define Id_eidt_paste 40005#define Id_help_about 40006#define Id_copy_paste 40007#define ID_COPY_PASTE40008 40008#define ID_POPUP_COPY 40009#define Id_popup_paste 40010#define Id_popup_cut 40011#define ID_POPUP_INFO 40012#define ID_INFO_A 40013#define ID_INFO_B 40014//Next default values for new objects// #ifdef apstudio_invoked#ifndef Apstudio_readonly_symbols#define _APS_NEXT_RESOURCE_VALUE 104#define _aps_next_command_value 40015#define _aps_next_control_value#define _APS_NEXT_SYMED_VALUE 101#endif#endif

Both the resource script file and the program file that needs to use the resource need to contain Resource.h. When referencing a resource, you need to indicate the ID of the resource, which is uniquely identified in both the resource and the program as the interface for the program and the resource.

Using Resources in programs

In the graphical user interface article, the use of resources in a program is also covered. The source code provided in this article also has the corresponding realization. Here is a detailed introduction to the use of resources in the program.
The source code references the icon and the menu resource as follows:

wcx.= LoadIcon(NULL// 图标......wcx.=// 菜单资源

The source code references the menu item ID and the dialog resource as follows:

        case ID_HELP_ABOUT:        {            DialogBox(                hinst, (LPCTSTR)IDD_DIALOG_ABOUT, hwnd, (DLGPROC)About                );            return0;        }

the Idi_icon_main, Idr_menu_main, Id_help_about, and idd_dialog_about here are resource IDs. The definition can be found in Resource.h.
Makeintresource is a macro that has the ability to convert resource IDs to resource names (string types), and many API functions use resource names when referencing resources.
Of course not only the interface will use the resources, any program can use the resources. The program in the resource is not only used with the graphical user interface. The resource can be arbitrary data. For example, it is possible to compile some configuration information, dynamic Connection library files into EXE resources. After the program runs, write the resource data to the file and then use it. This allows you to centralize all programs and data in one executable file.

VI: Windows Application Development Interface Resources

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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: and provide relevant evidence. A staff member will contact you within 5 working days.