How can I recover the dialog resource ID from a dialog window handle?

Raymond Chen

Occasionally, I see someone ask a question like the following.

I have the handle to a dialog window. How can I get the original dialog resource ID that the dialog was created from?

As we saw in our in-depth discussion of how dialogs are created from dialog templates, the dialog template itself is not saved anywhere. The purpose of a template is to act as the… well… “template” for creating a dialog box. Once the dialog box has been created, there is no need for the template any more. Consequently, there is no reason why the system should remember it.

Besides, if the dialog were created from a runtime-generated template, saving the original parameters would leave pointers to freed memory. Furthermore, the code that created the dialog box almost certainly modified the dialog box during its WM_INITDIALOG message processing (filling list boxes with data, maybe enabling or disabling some buttons), so the dialog box you see on screen doesn’t correspond to a template anywhere.

It’s like asking, “Given a plate of food, how do I recover the original cookbook and page number for the recipe?” By doing a chemical analysis of the food, you might be able to recover “a” recipe, but there is nothing in the food itself that says, “I came from The Joy of Cooking, page 253.”

0 comments

Discussion is closed.

Feedback usabilla icon