Why can’t I create my dialog box? Rookie mistake #2

Another class of rookie mistake is less obvious from looking at the code.

#define DLG_SAMPLE 1

DLG_SAMPLE DIALOGEX 32, 32, 210, 200
         14,92,182, 80

          hwnd, SampleDlgProc);

The problem with this code is that we forgot to call InitCommonControlsEx to register the listview class. More generally, the problem is that one of the controls on the dialog uses a window class that was not registered. (For example, maybe there's a rich edit control on the dialog, but nobody remembered to load the rich edit library.)

Next time, a sophomore version of this mistake.

Comments (8)
  1. Chris says:

    Heh, yeah, I had that problem one time. A listview-equipped dialog was firing the WM_INITDIALOG message and then promptly closing, well before I ever saw a WM_PAINT or WM_COMMAND. Took about 30 minutes of headscratching before I realized I never loaded comctl32.

  2. Brian says:

    This mostly happens when you’ve been working on a medium-large project for a while and start taking for granted comctl32 always being loaded.  Then you decide you want to write a quick and dirty little utility app.

  3. Dean Earley says:

    Ive fallen for this. Debugging isn’t helped by the fact that BOTH CreateDialog and GetLastError returned 0…

  4. Kevin says:

    Is there a better way to debug the cause of failures like this?  Back in the Windows 3.1 days, you could install a "debug" kernel that would print out trace messages for failures of this sort, but the only similar thing I can find for Windows XP is the "checked" build, but most of the copious trace output it produces is useful only to device driver writers and not application developers.

  5. Jules says:

    If I get a failure I can’t understand, something I’ve done in the past is switch to a Linux machine and run it under wine.  You can then step into the (reasonably well-commented) source code for the API functions and see what they’re doing that’s causing a problem.

    That’s how I finally figured out what happens to the user data pointer when you call CreateWindowEx with WS_EX_MDICHILD.

  6. Larry III says:

    Sometimes is works without calling initcommoncontrols. Why? Does any other apis call it?

  7. MattCho says:

    Why do dialog boxes have a hidden file menu?  (You can see it by clicking on "SPACE" + "ALT" and then hitting "SPACE" again.

Comments are closed.

Skip to main content