Hack Windows dialog boxes with Resource Hacker

Get more control over your 32-bit Windows applications with Resource Hacker--it is just what you've been looking for. Find out how to use this handy freeware utility to modify dialog boxes.

Resource Hacker is a handy freeware utility that allows you to modify just about any 32-bit Windows application or Windows itself. Although Resource Hacker is primarily designed as a mechanism for making cosmetic changes to an application, it can make functional changes as well. One of the more interesting changes you can make involves modifying an application's dialog boxes. Here's how.

Acquiring Resource Hacker and a note about modifying files
Resource Hacker takes up only 1.35 MB of disk space, works on Windows 9x/Me/NT/2000/XP, and it's free. Download the 541-KB zip file from the Resource Hacker Web site and unzip to your hard drive. Double-click the ResHacker.exe file, and you're ready to go. For a detailed review of Resource Hacker and word about the legality of modifying copyrighted software, check out this previous TechProGuild Daily Drill Down.

Opening a file with Resource Hacker
Resource Hacker will allow you to modify the dialog boxes in just about any Windows application with a few notable exceptions. First, the file that you are modifying must be a 32-bit Windows file. Sixteen-bit Windows files and DOS files won’t work. Second, some Windows files are compressed into a single EXE file. Resource Hacker cannot modify a compressed file. Other than this, you should be able to modify just about anything else. Remember, however, that anytime you modify an application, you risk making that application, or Windows itself, unstable or unusable. I therefore highly recommend that you make a copy of any file you intended to modify and only modify that copy.

With that said, open Resource Hacker and select the Open command from the File menu. This will allow you to open the file that you plan on modifying. I’ll introduce you to the concepts involved in modifying a dialog box by working with Notepad. After I’ve covered the basics while working with a relatively harmless application, I’ll move on to something a little more entertaining.

After you open Notepad (\Windows\notepad.exe), expand the Dialog container that’s found in the console tree. When you expand this container, you will see a series of subcontainers appear. Each of these subcontainers contains an object (usually named 1033). This object represents one of the application’s dialog boxes. If you click on a dialog box object, Resource Hacker will display the script behind the dialog box and a preview of what the dialog box looks like. For example, Figure A shows Notepad’s Page Setup dialog box and the script that makes it work.

Figure A
Here is Notepad’s Page Setup dialog box and the script used to create it.

The drag-and-drop technique
The easiest way to make a change to a dialog box is by dragging and dropping objects. Anything that you see on a dialog box can be moved or resized. In fact, I recently read an article in which someone didn’t like the size of the Windows Run prompt because it often hid part of the path name. Rather than living with the inconvenience, the person created a jumbo-size Run dialog box and expanded the prompt to fill the dialog box’s new size.

Using the drag-and-drop technique works really well. Moving and resizing objects is done in almost exactly the same manner as if the dialog box were a Microsoft Publisher document. As you rearrange and resize objects, the code related to the objects changes accordingly. When you’re done, you must simply click Resource Hacker’s Compile Script button and then save your changes.

Working with scripts
The drag-and-drop method works really well. I could just tell you about the drag-and-drop technique and then take the rest of the day off. The problem is, though, that Resource Hacker is capable of so much more than what can be achieved through simple dragging and dropping. If you are used to developing Windows applications, then the rest of what I’m about to show you should be a breeze. If not, then I will try to explain things the best that I can.

The first thing that you need to know about a Windows dialog box is that it is made up of independent objects called controls. A control can be just about anything. For example, a control could be a line of text, a drop down list, a text field, a button, or even a simple rectangle.

The other thing that you need to know is that controls are applied to a dialog box in a specific order. Sometimes, you might find that you are unable to move or resize a control. The reason for this is that if another control has been “drawn” on top of the control that you are trying to modify, then you cannot click on the buried control, at least not for editing purposes.

In such a situation, the only real way to edit the desired control is by manipulating the script that creates it. If you locate the line in the script that creates the control that you are trying to manipulate, you can move that line to a different position within the script and thus make it editable. Of course, as an alternative, you could just modify the script directly to achieve the desired results.

I’m going to show you the anatomy of a script. Before I do though, I need to point out a couple of things. First, even if you aren’t a developer, this is something that you need to pay attention to. I’m going to show you some more GUI-based editing techniques later on and unless you understand what I’m showing you here, those techniques will likely be over your head. The other thing that I need to say is that I could write an entire series of articles on Windows scripting. There is no way that I can thoroughly cover menu scripts in the amount of space that I have to work with. Instead, I am going to show you the basics so that I can move on to more GUI stuff.

If you look at Figure B, you’ll see an expanded view of the script that controls the dialog box shown in Figure A. The first few lines of the script set up elements such as the title of the dialog box, the language used, and the font that will be displayed. Just below the font listing is a bracket. All controls fall between the brackets and are designated by the word CONTROL.

Figure B
An enlarged version of the Page Setup dialog’s script

Just after the word CONTROL, is the text that applies to the control. This text falls within quotes. There are a couple of special things about the text line. First, if you don’t want any text displayed with the control, you can just put the two quotes together with nothing in between. Second, if you use the & sign in the middle of a line of text, then the character following the & sign will be underlined. Normally, this is used to designate a hot key. Simply underlining a character alone isn’t enough to create a hot key, but it does take care of the visual part.

The next part of a control is a control number. Every control on a dialog box must have a unique control number. Windows uses the control number to reference the control. For example, if you were to create a hot key, Windows would use the control number to figure out what the hot key was supposed to do. For preexisting controls, do not change the control number because you will almost always mess up the application by doing so.

After the control number, there are several tags that are applied to the control. These tags define the type of control and its behavior. Although space doesn’t permit me to talk about every possible tag, I do want to briefly discuss a few of them so that you’ll get an idea of how controls work.

If you look at the Page Setup dialog box in Figure A, you will notice that there are various control groupings. For example, there is a Paper section, an Orientation section, a Margins section, and so forth. Each of these sections uses a gray box to surround two or more controls. The box itself is also a control, though.

The first control on the list defines the Paper section. The BUTTON and BS_GROUPBOX tags define the control as a group box. If you look at the last three lines of the script, they use tags such as SS_WHITERECT and SS_GRAYRECT. These tags actually draw the piece of paper within the preview area; they have nothing to do with the gray group boxes.

The BUTTON tag is used for group boxes, but it is also used for actual buttons. The difference is that rather than using the BUTTON, BS_GROUPBOX tag, an actual button would use the BUTTON_BSPUSHBUTTON tags. Other common Windows objects also have corresponding control tags. For example, a drop down list is defined with the COMBOBOX, CBS_DROPDOWNLIST tags. You could even sort the items on the drop down list by applying the CBS_SORT tag. Plain text fields are designated by the STATIC tag and radio buttons are designated by the BUTTON, BS_AUTORADIOBUTTON tags.

One more tag that you probably need to know about is the TABSTOP tag. If you open any dialog box and press the Tab key a few times, you’ll see the cursor move from field to field. Since everything in the entire dialog box is technically a control, Windows needs to use the TABSTOP tag to figure out where to move the cursor when someone presses the tab key.

The last element of a control is the four numbers separated by commas. These numbers correspond to relative pixel positions. The first two numbers correspond to the horizontal and the vertical positions of the control’s top left corner in relation to the top left corner of the dialog box. Regardless of the dialog box’s position on the screen, the top left corner of the dialog box is always referenced as 0,0. Therefore, if the first two numbers of a control were 334, 50, then the control’s top left corner would be 334 pixels to the right of the dialog box’s top left corner and fifty pixels below it.

The last two numbers indicate the object’s size in pixels. For example, if the last two numbers are 4, 80, then the object will be four pixels wide and 80 pixels tall.

Using the Dialog Editor
Now that I have given you a crash course in Windows dialog scripts, let’s take a look at Resource Hacker’s Dialog Editor. To access the Dialog Editor, right-click on the dialog preview and select the Edit Dialog command from the resulting shortcut menu. If you launch the Dialog Editor from Notepad’s Page Setup dialog box, the Dialog Editor will look like the one shown in Figure C.

Figure C
The Dialog Editor can make global changes to a dialog box.

As you look at the Dialog Editor, there are a few things that you will probably notice. For starters, the top portion of the Dialog Editor corresponds to the first five lines of the dialog script. This is the section at the top of the script before any controls are defined. Although you can certainly edit a script manually, you can use the Dialog Editor to easily change the name of the dialog box, the dialog box’s size, font, font size, and even language.

You might also notice in the figure that the bottom section of the Dialog Editor contains lots of tags, with some tags highlighted in yellow. The tags on the list are all of the predefined tags that can be applied to a dialog box. The tags that are highlighted in yellow are the tags that are currently applied to this particular dialog box. You can turn tags on and off just by clicking on them.

Using the Control Editor
The Control Editor allows you to manipulate an individual control through the GUI. To access the Control Editor, simply right click on any control and select the Edit Control command from the resulting menu. When you do, you’ll see a dialog box similar to the one shown in Figure D.

Figure D
The Control Editor allows you how to manipulate individual controls.

The Control Editor allows you to modify the control’s caption, size, position, and location. You can also enable and disable tags by selecting them from the list. Earlier, I showed you the BUTTON tag and how it was used for group boxes, buttons, check boxes, radio buttons, and other objects. The BUTTONS tag is actually a control class. If you look at the figure, you will notice that BUTTON is the class name. All of the tags that are listed in the lower portion of the editor are tags that can be applied to buttons.

In this figure, I am editing the Portrait radio button. By simply selecting the BS_AUTOCHECKBOX tag, I could change this radio button into a check box. Furthermore, Resource Hacker is smart enough to know which tags can be used together. If you select a tag that isn’t compatible with the currently selected tags, the already selected but incompatible tags will be automatically deselected.

Adding a control
Another nice feature of Resource Hacker is that you can actually add your own controls to a dialog box. To do so, right-click on the approximate position where you want to add the control and then select the Insert Control command from the resulting shortcut menu. When you do, you will see the Control Editor, shown in Figure E.

Figure E
This version of the Control Editor is used for creating new controls.

What’s unique about this Control Editor is that you can click the icons at the top of the dialog box to control what type of control that you want to create. As you can see, Resource Hacker makes it easy to create buttons, text fields, slide bars, or just about anything else. When you select a control, the Control Editor automatically fills in the Class Name and selects the appropriate tags. The only thing left for you to do is to fill in the caption, adjust the control’s size, and assign a unique ID.

Have some fun
So far I have been showing you how to modify dialog boxes within Notepad. Now that you understand the basics of modifying dialog boxes, I thought that you might enjoy making some modifications that were more entertaining. The Resource Hacker can modify applications, but it can also modify Windows. If you would like to customize Windows, you can easily do so by editing the \WINDOWS\SYSTEM32\SHELL32.DLL file.

This file contains most of the dialog boxes used by the Windows operating system, including the Run prompt. By modifying this file, you can totally customize Windows' entire look and feel.

Editor's Picks

Free Newsletters, In your Inbox