February 7th, 2007

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
...
BEGIN
 ...
 CONTROL "",IDC_LISTVIEW,WC_LISTVIEW,LVS_REPORT |
         WS_TABSTOP | WS_BORDER,
         14,92,182, 80
 ...
END
DialogBox(hinst, MAKEINTRESOURCE(DLG_SAMPLE),
          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.

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.