September 22nd, 2006

Things you already know: How do I wait until my dialog box is displayed before doing something?

One customer wanted to wait until the dialog box was displayed before displaying its own dialog box. (Personally, I think immediately displaying a doubly-nested dialog box counts as starting off on the wrong foot from a usability standpoint, but let’s set that issue aside for now.) The customer discovered that displaying the nested dialog box in response to the WM_INITDIALOG message was premature, because as we all know, the WM_INITDIALOG is sent before the dialog box is displayed. The question therefore is, “How do I want until my dialog box is displayed before doing something?”

One proposed solution was the following code fragment:

case WM_INITDIALOG:
    PostMessage(hDlg, WM_APP, 0, 0);
    return TRUE;
case WM_APP:
    ... display the second dialog ...
    break;
  1. Why is this wrong? Hint: You definitely know the answer to this already.

  2. What is the correct solution? You probably know this already.
Topics
Code

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.