|
-
May 10th, 1999, 11:07 AM
#1
Basic question about constructors and initializers in VC++
Hi,
Why does Visual C++ provide the OnInitDialog function when the dialog already has a constructor , i.e, can I not perform all initializations for a dialog in the constructor of the dialog itself (instead of in the OnInitDialog function) ?
Thanks in advance.
mc
-
May 10th, 1999, 12:51 PM
#2
Re: Basic question about constructors and initializers in VC++
Hi,
When an instance of your dialog class is created and its constructor is called, the actual dialog is not created so in the constructor, the common controls in your dialog are not created, if you will try to access those controls you will get well known GPF buddy. But when the function OnInitDialog gets called, the dialog is created i.e. all controls on your dialog box are created and that's why onInitDialog is the safest place to initialize controls on the dialog.
Yes, if you have some member veriables in your dialog class then definitely you can initialize those variables in the constructor.
I hope this answer will give you an answer.
Thanks
Chetan
Nothing is imposible.
-
May 10th, 1999, 04:46 PM
#3
Re: Basic question about constructors and initializers in VC++
Simple. The constructor is nothing more than straight C++ and for the most part has nothing to do with a Windows dialog, or even Windows. It allows you to add any initialization code before the dialog is created by Windows.
However, the OnInitDialog() is actually invoked by MFC when the operating system (Windows) sends a message (WM_INITDIALOG) to the dialog's window procedure. The only things that you can't do in the constructor is manipulating the dialog's controls, since they do not exist yet.
Windows knows *nothing* about C++ constructors; if it did, C, VB, Delphi, PowerBuilder, etc. programmers would not be able to write Windows programs!
Regards,
Paul McKenzie
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|