Date: | February 7, 2007 / year-entry #44 |
Tags: | code |
Orig Link: | https://blogs.msdn.microsoft.com/oldnewthing/20070207-04/?p=28113 |
Comments: | 8 |
Summary: | 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... |
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
Next time, a sophomore version of this mistake. |
Comments (8)
Comments are closed. |
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.
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.
Ive fallen for this. Debugging isn’t helped by the fact that BOTH CreateDialog and GetLastError returned 0…
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.
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.
Sometimes is works without calling initcommoncontrols. Why? Does any other apis call it?
Why do dialog boxes have a hidden file menu? (You can see it by clicking on "SPACE" + "ALT" and then hitting "SPACE" again.
PingBack from http://geeks.netindonesia.net/blogs/lontong/archive/2009/01/18/win32-tiny-tip-on-using-common-controls.aspx