July 8th, 2005

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

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.”

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.

Feedback