August 20th, 2014

If you're looking for the code that displays a particular dialog box, the most directly way to find it is to look for the dialog box

Suppose you are working in a large or unfamiliar code base and you want to know where the code is that displays a particular dialog box or message box or something. Probably the most direct way of figuring this out is to look for the strings. Say there is a message box that asks for user confirmation. “Are you sure you want to frobulate the flux capacitor?” Search for that string in your source code. It will probably be in a resource file.

resource.rc:IDS_CONFIRM­FROBULATE "Are you sure you want to frobulate the flux capacitor?"

Great, now you have the string ID for that message. You can perform a second search for that ID.

resource.h:#define IDS_CONFIRM­FROBULATE 1024
resource.rc:IDS_CONFIRM­FROBULATE "Are you sure you want to frobulate the flux capacitor?"
maintenance.cpp:   strPrompt.LoadString(IDS_CONFIRM­FROBULATE);

If the thing you are searching for is a dialog box or menu item, then be aware that there may be an accelerator in the string, so a straight grep won’t find it.

No matches for "Enter the new name of the frobulator:"

For a dialog box, you can tap the Alt key to make the accelerator show up, so you can search for the right string. For a menu, you invoke the menu via the keyboard. Or in either case, you can disable the Hide underlined letters for keyboard navigation setting.

resource.rc:  LTEXT "Enter the ne&w name of the frobulator:",

I tend to be lazy and instead of using any of those tricks to make the underlines show up, I just search for a shorter string and hope that the accelerator isn’t in it.

resource.rc:  LTEXT "Enter the ne&w name of the frobulator:",

“But Raymond, hitting the Alt is just a quick tap on the keyboard. Surely you can’t be that lazy!” Right. If the dialog box were right in front of me, then I could tap the Alt and be done. But usually, when I am investigating this sort of thing, it’s because somebody has sent a screen shot and asks, “Where is the code that displays this?” Tapping Alt on a screen shot doesn’t usually get you very far.

Once you find the code that displays the dialog box or message box or whatever, you can then study the code to answer follow-up questions like “What are the conditions under which this dialog will appear?” or “Is there a setting to suppress this dialog?”

Topics
Other

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments

Discussion are closed.