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?"

Comments (18)
  1. Brian_EE says:

    Maybe I'm just too old and seasoned, but isn't this something you learn in the class "Basic Debugging 101"? I wouldn't expect to have to tell someone how to do this.

    [Part of the reason I post these things is so that I have to explain it only once. -Raymond]
  2. Joshua says:

    I've seen cases where this technique yielded no message. Then you know you've got trouble coming.

  3. Mike Caron says:

    @Joshua: Or, cases where it has yielded dozens of messages. Both cases are vexing :)

  4. SimonRev says:

    While I understand why Microsoft did it, I still rue that Win2k started hiding the accelerators by default.

  5. DWalker says:

    Flux capacitors always need to be frobulated.  There should not be a dialog box asking the user "Are you sure you want to frobulate the flux capacitor?"!  Everyone knows that.

  6. Mc says:

    Or some idiot (sorry I mean Enterprise Architect)  has decided that all messages should be stored in the database…

  7. Katie says:

    Don't forget the cases where the screenshot is of a blank dialog box…

  8. WAitken says:

    @Mc.   it took me three reads to realize that you didn't mean [USS] Enterprise Architect.

  9. John says:

    You should start a new tag: ICBIHTWT – I Can't Believe I Had To Write That. Great article, sounds similar to situations I've had to deal with in the past, not sure how these kids get out of these CS programs without these skills.

  10. Mark VY says:

    typo alert: directly –> direct??

  11. Nico says:

    I realize that "grep" has more or less become a generic term, but it made me wonder: do you use something like coreutils for Windows, or do you stick with Windows analogs?  For example, grep vs findstr.

    [Neither. I use a content indexer. -Raymond]
  12. alegr1 says:

    When you get a screenshot with a dialog box in one of Far Eastern languages, *that's* when you're in trouble.

  13. blockeduser says:

    It's not the first time mr. chen alludes to unix tools.

    Consider this article, which mentions "wc -l": blogs.msdn.com/…/7885570.aspx

    Incidentally, thanks for the nice blog, mr. chen, and for updating it frequently.

  14. Drak says:

    @Raymond: 'Tapping Alt on a screen shot doesn't usually get you very far.'

    Clicking the 'X' to close a window in a screenshot also does not work, but I still do it quite often ;)

  15. ian.m.goldby@eon.com says:

    "When you get a screenshot with…"

    You get a screenshot? All I get is a voicemail telling me "the program crashed". (9 times out of 10 "crashed" doesn't even mean "stopped running".)

  16. Medinoc says:

    Note: Unless it was reverted in Windows 8 or 8.1, the phrase "disable the *Hide underlined letters for keyboard navigation* setting." is now incorrect. It has been replaced with "enable the *Show underlined letters for keyboard navigation* setting." since the earliest currently "supported"† Windows version.

    †In quotes because Visual Studio.

  17. Macrosofter says:

    Sorry for vaguely related question, but why in Windows 8.x keyboard selection on Start Screen is visible only if underlined letters for keyboard navigation are also enabled? Is it now the global way to say Windows that user uses keyboard?

  18. Medinoc says:

    @Macrosofter: I know there are two settings in SystemParametersInfo – SPI_SETKEYBOARDPREF and SPI_SETKEYBOARDCUES – but I have no idea what UI element controls the former. It is possible that the same checkbox control(s?) both.

Comments are closed.