The clever use of MFC *. RC and resource. H files

Source: Internet
Author: User

This is a software system completed by several people. Network optimization software system based on the mo control and MFC platform. I wrote the operation function of the main menu.

 

Because a platform is divided by several people and cannot be managed by the VSS version due to geographical reasons, the platform completes its respective functional modules on the basis of the prototype system, and then integrates them together. This will cause many problems:

 

1. How do I add the dialog resources designed by myself and their corresponding classes to others' systems?

2. What modifications should I make for mainfrm. CPP/mainfrm. h?

 

First, find the name of the newly added dialog resource. The name of the new module is as follows:

# Define idd_polygon_property 400
# Define idd_line_property 401
# Define idd_property_node 402
# Define idd_polygon_manipulaton 403

 

Well, we can clearly understand the modules we have added, and we can also easily find the classes (cxx. CPP, cxx. h). We wrote this by ourselves. It should be clear...

 

For the convenience of narration, we take our own project as me and call the project to be integrated as he.

Step 1:

Well, after finding it, we will first copy these source files to the directory of the He project to be integrated :). Remember to manually add these files after opening the project.

Step 2:

The *. RC file and resource. h file under the me project and the he project should be carefully compared. These two files control all resource files, including dialog and dialog controls (buttons, edit, etc.), menu, toolbar, bitmap, icon, string table, version, accelerator, etc.

====> In comparison, Leo recommends a small tool. You can get twice the result with half the effort, that is, SVN.
You may only know that this is a version management tool, but after installation, select the text file to be compared-> right-click-> diff, then you will find its nubility feature. Haha ~

Step 3:

Through comparison, you can quickly find the *. RC and resource. h of your me project are different from those of the He project, extract the new part, and add the corresponding files to the he project. Of course, in resource. H, we will find that the values after # define XXXX 489 are sometimes repeated, which requires manual modification. It is best not to conflict with define in the he project.

Note: For Menu modification (for example, adding a level-1 menu), you can go *. added a dialog resource to RC, which will be in *. add two things to RC, such as dialog1 (Chinese (P. r. c .) resources type), then *. RC and resource. H is changed as follows:

 

Note: There are many types of dialog. The added types are automatically written together by Vs, for example (Chinese (P. r. c .) resources) Types of dialog, (English & American resource) dialog will be put together ~; The control resources in resource. h can be reused, for example

# Define idc_radio1 1001 can be used in different dialog, And the IDs are all idc_radio1. There are also some disadvantages of doing this, that is, you change one will affect multiple, pull the whole body ~

* In the RC file:

//////////////////////////////////////// /////////////////////////////////////
//
// Dialog
//

Idd_dialog1 dialogex0, 0,383,180
Style ds_setfont | ds_modalframe | ds_fixedsys | ws_popup | ws_caption | ws_sysmenu
Caption "dialog"
Font 8, "Ms shell DLG", 400, 0, 0x1
Begin
Defpushbutton "OK", idok, 205,159, 50, 14
Pushbutton "cancel", idcancel, 320,159, 50, 14
Pushbutton "button1", idc_button1, 25, 26, 50, 14
Control "radio1", idc_radio1, "button", bs_autoradiobutton, 101,32, 38,10
ComboBox idc_combo1, 37,58, 48,30, cbs_dropdown | cbs_sort | ws_vscroll | ws_tabstop
Groupbox "static", idc_static, 153,92, 48 ,40
End

...

...

...

//////////////////////////////////////// /////////////////////////////////////
//
// Designinfo
//

# Ifdef apstudio_invoked
Guidelines designinfo
Begin
Idd_dialog1, Dialog
Begin
Leftmargin, 7
Rightmargin, 370
Topmargin, 7
BOT margin, 173
End
...
...
End
# Endif // apstudio_invoked

# Endif // Chinese (P. R. C.) Resources

 

Changes in resource. h:

# Define idd_dialog1 130

..

..

# Define idc_radio1 1001
# Define idc_combo1 1002 // This is the control resource included in your newly added dialog resource. It will also be define in resource. h.

 

 

Okay. Finally, let's build it. If there is any error, check if you forget a define or * in the me project *. in RC, a menu or dialog box is not copied to the he project, or the copy position is messy .. The method is very clear. You can open *. RC in notepad to see how the organization works.

 

 

In this way, when we want to integrate the MFC project into other projects in the future, apart from the source files, we can copy them, and the dialog set by our hard work can be retained, which is quite good ~

 

 

Recently, we have found a quicker method:

Directly open two projects and copy the related RC to the RC of another project, but do not forget to copy the corresponding ones. h /. CPP add to the corresponding project. I forgot that vs can open multiple projects at the same time ~

 

Someone asked me if I could change the name of the generated project ,... Well, of course we can. We only need to operate on the following files:

Gui. vcproj. accessconsys. zlh. User

Gui. sln

Gui. vcproj.55b45e7425f1495. administrator. User

Gui. vcproj

For example, you need to open the GUI-> bupt_gui in notepad, and change the corresponding GUI to bupt_gui. Of course, the above file name is also changed to bupt_gui .***

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.