Click here to Skip to main content
Click here to Skip to main content

Resource Comparer

By , 23 Aug 2004
Rate this:
Please Sign up or sign in to vote.

Sample Image - rcomparer.gif

Introduction

I have been using the resource editor in Visual C++ for a while to create programs in multiple languages. It works great and is very easy to use. But it is quite hard to keep all languages synchronized. For example, if you upgrade your program and add a control, you will probably need to add it in other languages as well. This is easy, if you remember to do it Smile | :) . To solve this, I created a tool that compares two resource-files (.rc) and notices if something doesn't look right (like missing controls, different window styles...).

Using the program

RC is quite straightforward to use. Select the two files you want to compare, and click on Compare. After a couple of seconds is the comparing done and you see the result. If you have resources in multiple languages in a file and just want to read a specific language, write the language string in the language boxes (like LANG_ENGLISH for English). Leave this empty if you want to read all languages.

In the bottom of the window are error messages if the program fails to parse the files. Detected languages will also be found here.

Another feature of the program is that it could extract all strings from a file. This is very useful if you want to spell check your program, just click on "Make string list" and copy the log to a word processor. Only "File 1" will be used in this function.

If you want to see all resources in "File 1", click on "Make resource tree". If you uncheck "Only IDs", then you will also see all settings that the program has found (like strings, style of controls).

The fourth button, "Translation table", creates a table where you see how strings are translated. If you check "LocalizeRC INI", the output will be written as an INI-file to use with LocalizeRC (another program at CodeProject).

What it checks

Resource Comparer checks these:

  • Menus
    • Strings
    • Settings (Checked, Grayed...)
    • Structure (Order of items)
  • Toolbars
    • Structure
  • Dialogs
    • Captions
    • Style settings (Border, system menu...)
    • Extended style settings (Tool windows, client edge...)
    • Tab order
  • Controls
    • Strings
    • Type (So controls with same ID are of the same type)
    • Style settings
    • Extended style settings
    • Help ID
  • Strings
    • %-words
    • \-characters
  • Bitmaps
  • Icons
  • Cursors

The program does not check:

  • Accelerators
  • Version
  • Data (strings) in combo boxes
  • Size of bitmaps, toolbars, icons or cursors.

Note: The program will fail to parse the file if you are using condition settings on the resources.

Strings

Checking strings could be very important. The program gives you five methods to use:

  1. None:

    Don't check strings.

  2. Check %-words

    Let's say you have a string like this: "Your name is: %s". You use this string with CString::Format to replace "%s" with the user name. Then it is very important that in all other languages, the string also includes "%s". If it's not, then your program will probably crash when it runs CString::Format. Therefore, check the program that all strings have the same number and order of %-words. So, if you have a string like "%s, %d" in one file, and another string like "%d, %s" in a second file, then you will get an error message.

  3. Check \-characters

    This is very similar to (2). Let's say you have a string like this: "Hello\nworld". Then you translate it, and make a little error: "Hello\world" (no, they are not the same - look again!). It is very easy to make mistakes like that; I have done it myself several times. But now, I have this program that will warn me if I do it again Smile | :) .

  4. %- and \- problems

    Uses both test 2 and test 3.

  5. Compare full string

    This checks if strings match completely. This is useful if you want to see what changes you have done from an old version.

All strings are running this test, also string in dialogs and menus.

Example

As a programmer, I know that it is more interesting to look on an example than reading a manual, so let us look on a log:

Comparing menus:
    Comparing menu resource: IDR_MAINFRAME
        Different style in ID: ID_FILE_CHECKED (1: CHECKED, 2: )
        Different menu structure. Item 4 is ID_FILE_SAVE in 1, 
                                          and ID_FILE_SAVE_AS in 2
        Different menu structure. Item 5 is ID_FILE_SAVE_AS in 1, 
                                             and ID_FILE_SAVE in 2

Comparing toolbars:
    Comparing toolbar resource: IDR_TOOLBAR1
        Different toolbar structure. Item 1 is ID_FILE_NEW in 1, 
                                             and ID_FILE_SAVE in 2
        Different toolbar structure. Item 2 is ID_FILE_SAVE in 1, 
                                              and ID_FILE_NEW in 2

Comparing dialogs:
    Comparing dialog resource: IDD_ABOUTBOX
        String error in IDOK: Different number of %-signs ('OK', 'OK - %s')
    Comparing dialog resource: IDD_TEST_DIALOG
        Dialog style doesn't match ( DS_MODALFRAME|WS_POPUP|
                           WS_VISIBLE|WS_CAPTION|WS_SYSMENU, 
                           WS_POPUP|WS_VISIBLE|WS_CAPTION|
                           WS_SYSMENU|WS_THICKFRAME)
        Different style settings on control ID: IDC_LISTCONTROL 
                           (1: 'LVS_REPORT|WS_BORDER|WS_TABSTOP', 
                           2: 'LVS_REPORT|LVS_OWNERDRAWFIXED|
                           WS_BORDER|WS_TABSTOP')
        Couldn't find control ID: IDC_STATIC_EXTRA
        Different items count (6 in 1, 5 in 2)

Comparing strings:
    String error in IDS_TOFORMAT: Different %-words (%s and %d)
    String error in IDS_SLASH: Different number of \-signs 
                         ('Hello\r\nworld.', 'Hello\r\\world.')
    String error in IDS_ULTRA: Different %-words (%s and %d), 
                             Different \-characters (\r and \n)

Comparing bitmaps:
    Couldn't find bitmap: IDB_BITMAP_EXTRA in file 2

Comparing icons:
    Couldn't find icon: IDI_ICON_EXTRA in file 2

Comparing cursors:
    Couldn't find cursor: IDC_CURSOR_EXTRA in file 2

As you can see, we have checked menus, toolbars, dialogs, strings, bitmaps, icons, and cursors. In the menu section, we see that in one of the files, one menu item is checked, in the other it's not. Two menu items also have swapped places.

In the toolbar section, the buttons ID_FILE_NEW and ID_FILE_SAVE have swapped places.

In the dialogs, there are several errors. The button IDOK in the about box has a percent sign in the second file, but in the first, there is none. In the other dialog, we see that the dialog has different styles in the two files. The list has the "Owner draw" value in the first file, but not in the second. We are also missing a control in the second file, IDC_STATIC_EXTRA. Therefore, we do not have the same number of controls in the two files.

We have problems with three strings. In IDS_TOFORMAT, we are using "%s" in the first file, and "%d" in the second. In the string IDS_SLASH, there is a misspelling, \\ should be \n. In the last, we have a string that has both types of errors.

We also see that we are missing a bitmap, icon, and a cursor in the second file.

Points of Interest

There is a special ID you can use to have multiple number of items with the same ID, IDC_STATIC (this is the default ID for new static text controls). When Resource Comparer compares dialog controls, it compares items with the same ID. So when more than one control has the same ID, we have a problem. Resource Comparer solves this by using the tab order to figure out how to match the controls. The first control with IDC_STATIC will be compared with the first control with the same ID in the other file. And the second control will be compared with the second control in the other file, and so on.

If you look at the code, you may see that I have written it quite fast. But it seems to work well and is enough for me. Parsing the resource files was the hardest thing to do. The program makes a lot of assumptions but it seems to be clever enough Smile | :) . As I said before, conditions are not supported. When you use conditions, #if statements are added in the file, and I haven't cared about this. But if you are interested to solve this problem, just go for it Smile | :) . And I know the output could be better, but since I will not use this program very often, I really don't care about this.

Unicode is supported, but not multi-byte characters in ANSI.

I have only tested this program on projects made in VC6, but I don't think there should be any problems with later versions.

Links and Miscellaneous

CodeProject

History

  • 21 August, 2004 - Version 1.2. Support for Unicode. Applied a minor fix by Graham Pye. Captions in dialogs are now tested.
  • 4 August, 2004 - Version 1.1. "Help ID" is now checked on controls. Controls with ID IDC_STATIC are now compared. If more than one control has this ID, the tab order will be used to figure out how to match them. The program can now create INI files to use with RC Localization Tool
  • 10 July, 2004 - Initial version.

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

About the Author

PEK

Sweden Sweden
PEK is one of the millions of programmers that sometimes program so hard that he forgets how to sleep (this is especially true when he has more important things to do). He thinks that there are not enough donuts in the world. He likes when his programs works as they should do, but dislikes when his programs is more clever than he is.

Comments and Discussions

 
GeneralProblem with new resources PinmemberSunilApte3-Sep-10 1:18 
GeneralMore checking please Pinmember-273C22-Oct-06 22:43 
GeneralText Fits Checker PinmemberRob Hudson13-Jun-05 5:57 
GeneralRe: Text Fits Checker PinmemberGrahamPye10-Aug-05 13:38 
GeneralRe: Text Fits Checker PinmemberRob Hudson10-Aug-05 22:20 
GeneralCompare the two RC and push the difference to the localized RC Pinmemberjchen80003-Mar-05 18:43 
GeneralRe: Compare the two RC and push the difference to the localized RC PinmemberPEK4-Mar-05 7:49 
General"" parsed as \" PinmemberJohn Noël24-Aug-04 23:27 
GeneralRe: "" parsed as \" PinmemberPEK26-Aug-04 10:11 
GeneralRe: "" parsed as \" [modified] Pinmemberardjand10-May-07 22:19 
GeneralExcellent Pinmember.dan.g.24-Aug-04 14:10 
GeneralRe: Excellent PinmemberPEK26-Aug-04 10:23 
GeneralDIALOG vs DIALOGEX PinmemberGrahamPye18-Aug-04 0:42 
GeneralRe: DIALOG vs DIALOGEX PinmemberPEK18-Aug-04 1:28 
QuestionUnicode support? Pinmemberprcarp9-Aug-04 5:18 
AnswerRe: Unicode support? PinmemberPEK9-Aug-04 22:46 
GeneralRe: Unicode support? PinmemberGrahamPye17-Aug-04 0:49 
GeneralRe: Unicode support? PinmemberPEK17-Aug-04 23:43 
GeneralRe: Unicode support? PinmemberGrahamPye18-Aug-04 0:32 
GeneralRe: Unicode support? PinmemberPEK18-Aug-04 1:23 
GeneralAmazing! PinmemberObliterator9-Aug-04 1:06 
GeneralRe: Amazing! PinmemberPEK9-Aug-04 2:33 
GeneralResource IDs may not be unique PinmemberMathieu Jacques14-Jul-04 7:04 
GeneralRe: Resource IDs may not be unique PinmemberPEK15-Jul-04 0:57 
GeneralRe: Not forbidden if in a different dialog PinmemberMathieu Jacques16-Jul-04 3:58 

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

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

| Advertise | Privacy | Mobile
Web01 | 2.8.140415.2 | Last Updated 24 Aug 2004
Article Copyright 2004 by PEK
Everything else Copyright © CodeProject, 1999-2014
Terms of Use
Layout: fixed | fluid