Click here to Skip to main content
15,917,642 members
Articles / Programming Languages / C++
Article

Order Resource File

Rate me:
Please Sign up or sign in to vote.
3.38/5 (4 votes)
20 Feb 2006 27K   223   14   7
OrderResourceFile sorts the #define values in the resource.h file in alphabetical order. The #define values are also renumbered in sequence, starting with the number 1024.

Introduction

OrderResourceFile sorts the #define values in the resource.h file in alphabetical order. The #define values are also renumbered in sequence, starting with the number 1024.

  1. Execute OrderResourceFile.exe in the same folder that has your "resource.h" file.
  2. Manually copy the new #define values from OrderResourceFile.txt to your "resource.h" file.

Background

This is a simple and useful tool for keeping your code clean.

Using the code

Select and copy (to the clipboard) the text lines above the "#define _APS" values from your OrderResourceFile.txt.

Open "resource.h" and carefully paste these values over the old #define values:

//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by MyProgram.rc
//

#define MYDIALOG_IDC_BUTTON_1 1024   // START PASTING HERE
#define MYDIALOG_IDC_BUTTON_2 1025
#define MYDIALOG_IDC_BUTTON_3 1026
#define WM_DIALOGSTATE_01 1027
#define WM_DIALOGSTATE_02 1028
#define WM_DIALOGSTATE_03 1029      // STOP PASTING HERE

// Next default values for new objects
// 
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE        201
#define _APS_NEXT_COMMAND_VALUE         32768
#define _APS_NEXT_CONTROL_VALUE         206
#define _APS_NEXT_SYMED_VALUE           134
#endif
#endif

Points of Interest

Sometimes Visual Studio .NET 2003 complains with an "end of file" error in resource.h if I paste in the areas not specified above.

History

Original article created.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Engineer
United States United States
C++, MFC, ActiveX, DirectShow, GDAL

Comments and Discussions

 
GeneralTwo controls with same id in resource file Pin
hariakuthota4-Sep-08 0:02
hariakuthota4-Sep-08 0:02 
GeneralDangerous approach Pin
Damir Valiulin26-May-06 6:23
Damir Valiulin26-May-06 6:23 
AnswerRe: Dangerous approach Pin
DvssCoder19-Jun-06 17:45
DvssCoder19-Jun-06 17:45 
Damir Valiulin wrote:
One problem is bitmap IDs when used in dialogs. THe dialog template in the .rc file does not store named ID but rather the value of that ID. So if you renumber a bitmap ID that is used in a dialog, that dialog will be broken.


In Microsoft Visual Studio .NET 2003 (the version I tested this with), Bitmaps are referenced by the name ID that matches the name ID in the resource.h file. So in this version there won't be a problem if you change the number associated with #define VALUE in resource.h


Damir Valiulin wrote:
Second concern is the sequence of numbers you are using. MSDN recommends to stick to certain numerical ranges for menu commands and controls.


Except for "ID_ commands 0x8000 -> 0xDFFF," there are no possible conflicts with renumbering your ID values in resource.h

The following is from http://msdn2.microsoft.com/en-us/library/t2zechd4.aspx

"
We strongly recommend you do not defined IDs outside the recommended ranges. Even though the lower limit of many of these ranges is 1 (0 is not used), common convention starts practical use of IDs at 100 or 101.

Prefix Resource type Valid range
IDR_
multiple
1 -> 0x6FFF

IDD_
dialog templates
1 -> 0x6FFF

IDC_,IDI_,IDB_
cursors, icons, bitmaps
1 -> 0x6FFF

IDS_, IDP_
general strings
1 -> 0x7FFF

ID_
commands
0x8000 -> 0xDFFF (The only *possible* conflict given your number of #defines is below #32,768)

IDC_
controls
8 -> 0xDFFF
"


Damir Valiulin wrote:
And third, there's already an exellent tool for this called ResOrg and it provides lots of flexibility in renaming resource IDs: http://www.codeproject.com/macro/resorg.asp


If anything this simple code project can be used as a learning tool.
Generalcould be useful Pin
kzipperer3-Mar-06 1:43
kzipperer3-Mar-06 1:43 
Generalone doubt... Pin
Sumit Kapoor28-Feb-06 12:58
Sumit Kapoor28-Feb-06 12:58 
GeneralMaybe useful, but... Pin
YoSilver21-Feb-06 1:55
YoSilver21-Feb-06 1:55 
GeneralRe: Maybe useful, but... Pin
Chris Conn21-Feb-07 9:16
Chris Conn21-Feb-07 9:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.