How do I get the title of a dialog from a dialog resource?

A customer submitted the following question:

We are developing automated tests for our application. Among other things, our application uses property sheets, which means that the name of the tab is stored as the title of the dialog template resource. Since we want our automated tests to run on all language versions of our application, we don't want to hard-code the tab names in our automated test. I have not been able to find any information on how to programmatically extract the dialog titles from the dialog resources. Any pointers would be appreciated.

I replied with some pointers:

The customer was grateful for the pointers, then asked:

Then the only way to do this is to load the dialog resource and parse the data looking for the string I want? Is it even possible to do this in C#?

Well it depends on what your definition of "the only way" is.

At the end of the day, somebody has to load the dialog resource and parse it, because after all that is what you said you want to do: "I want to get the title of the dialog from the dialog resource." The alternative is, what, psychic powers?

There is no dialog template parsing library that comes with Win32. If you don't want to do the parsing, then maybe you can find somebody else who will. And if you're lucky, that other person may even have provided a C# interface.

Comments (13)
  1. davep says:

    There's the old "Chinese" saying "may you live in interesting times". The Chen-version of this is "may you get an interesting response"!.

  2. Ivo says:

    Another way is to create the dialog window and get its caption. Not as elegant as parsing the template data, and has some potential problems, but might be good enough for the customer's case.

  3. Joe says:

    My psychic powers say that what they really wanted to do was to create the dialog with no name in the tab, then use some data they get from elsewhere to see what the title should be.  then the question says "How do I change the title on a tab of a property page?"

  4. Timothy Byrd says:

    We will likely have a similar issue here. When that happens, I'll suggest giving the (translated) .rc files to the test team, and then they can parse the DIALOG(EX) to their hearts content.

  5. Alex Grigoriev says:


    LoadLibraryEx(LOAD_LIBRARY_AS_DATAFILE),  CreateDialog, GetWindowText, DestroyWindow. But it may fail if custom controls are used.

  6. Simon says:

    I don't think their follow-up question is unreasonable, myself.

    Asked for advice on how to extract the title, you've replied with a bunch of file format info – it seems quite natural that they'd want to confirm that since you hadn't mentioned one, there wasn't a API for doing this kind of thing. They may be technically fine with parsing the files themselves, but just not wanting to do it that way if there was a more standard solution. Don't want to end up on DailyWTF, afterall…

  7. Tergiver says:

    I couldn't resist the "challenge", and I was bored today.…/parsing-win32-dialog-templates

  8. chrismcb says:

    Ivo I suspect they want to verify that the caption of the window is the caption that is in the resource (hence the whole automated test thing)

    Of course I have it on good authority from expensify that you can only cook 1.6 oz hamburgers in c#

  9. Ivo says:

    @Chris – I don't think so. Imagine if you loaded the dialog resource in memory. You can either parse the template data yourself, or use CreateDialogIndirect + GetWindowText. What if you get different results? That would mean that either your test code is wrong, or CreateDialogIndirect is wrong. My money is on your code being wrong.

    But as Alex mentioned, this will not work if the dialog is using an unknown control class (either a custom control, or if you didn't call InitCommonControls, or if you didn't load the rich text DLL).

  10. Gabe says:

    Joe: I think you're mistaken. They're doing automated testing, which implies that either they want to verify that the correct title is going to be displayed, or they need a way to find it in order to get at its controls.

  11. .net resource says:

    c# dialogs are not saved as win32 resources.

  12. Markus B. says:

    I once wrote a parser for win32 ressources. It was quite fun to do it, I even did it in C#.

  13. Alex Cohn says:

    @Tergiver: well done!

Comments are closed.

Skip to main content