Why are dialog boxes initially created hidden?
You may not have noticed it until you looked closely,
but dialog boxes are actually created hidden initially,
even if you specify WS_VISIBLE in the template.
The reason for this is historical.
Rewind back to the old days (we're talking Windows 1.0),
graphics cards are slow and
CPUs are slow and memory is slow. You can
pick a menu option that displays a dialog and
wait a second or two for the dialog to get loaded
off the floppy disk. (Hard drives are for the rich
kids.) And then you have to wait for the dialog box
to paint.
To save valuable seconds, dialog boxes are created
initially hidden and all typeahead is processed while
the dialog stays hidden. Only after the typeahead
is finished is the dialog box finally shown.
And if you typed far ahead enough and hit Enter,
you might even have been able to finish the entire dialog
box without it ever being shown! Now that's efficiency.
Of course, nowadays, programs are stored on hard drives
and you can't (normally) out-type a hard drive, so this optimization
is largely wasted, but the behavior remains for compatibility
reasons.
Actually this behavior still serves a useful purpose:
If the dialog were initially created visible, then the
user would be able to see all the controls being created
into it, and watch as WM_INITDIALOG ran (changing default
values, hiding and showing controls, moving
controls around...) This is both ugly and distracting.
("How come the box comes up checked, then suddenly unchecks
itself before I can click on it?")