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

Comments (4)
  1. Paul Orrungroj says:

    What’s the recipe on page 253?

  2. Considering the number of editions JoC has been through, could be anything from Rabbit Stew (first, catch a rabbit) to microwave popcorn ;)

  3. Anonymous says:

    In my edition it’s your choice of: "Creamed Chipped Beef", "Chipped Beef in Creole Sauce", "Chipped Beef in Cheese Sauce", "Chipped Beef and Sweet Potato Casserole" or "Chipped Beef or Corned Beef in Canned Soup."

  4. Anonymous says:

    Early editions of The Joy Of Cooking only had 200 pages. The reference to page 253, exploits a well-known buffer overrun error which causes the end of each edition to be corrupted with pictures of ham sandwiches. Later editions corrected this error by expanding the number of pages to 928:

    http://www.amazon.com/exec/obidos/tg/detail/-/0026045702/ref=dp_proddesc_1/102-4684116-3275367?%5Fencoding=UTF8&n=283155&v=glance

    HTH,

    TC

Comments are closed.