Re: OnInitDialog not getting called because of DoModal
On Tue, 27 Mar 2007 10:59:00 -0500, Joseph M. Newcomer
<newcomer@flounder.com> wrote:
YOu got it wrong.
When you create a dialog (not a dialog-based app), you must add an OnInitDialog handler
using the classwizard (well, the properties sheet). Its declaration must be
virtual BOOL OnInitDialog();
if you just added a non-virtual method, it won't get called.
Using the virtual keyword in derived classes is optional. This is a
double-sided weakness of C++:
1. When you add a member function to a derived class, you must look at all
the base classes to ensure you don't override a virtual function.
2. When you add a virtual function to a base class, you must look at all
the existing derived classes to make sure you don't cause one of their
member functions to override the one you just defined.
Overriding and accessibility are orthogonal; that is, a derived class
doesn't require access to a virtual function in order to override it. This
is a bit of a mess, and C# definitely learned some lessons from it.
If you added something that
has a message-map entry for WM_INITDIALOG, it won't get called.
Actually, that's a no harm, no foul practice. It's just redundant since
WM_INITDIALOG is one of the few messages whose handler is virtual.
Don't do things by hand when there are tools that do it for you, unless you really know
what you are doing.
Agreed!
--
Doug Harrison
Visual C++ MVP