Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dialog initialisation

Status
Not open for further replies.

oxie

Programmer
Aug 23, 2002
7
FR
Hi,

I have a main dialog box with a button. This button displays another dialog box. I want to initialize some controls on this second dialog box but I want these controls to be initialized ONCE : when the program starts.
If I try this :

void CMainDlg::eek:nBnClicked()
{
CMyDialog myDlg;
myDlg.ctrl_checkbox.EnableWindow(FALSE);
myDlg.DoModal();
}

...I get an "Debug Assertion Failed" error which I understand because the dialog box has not been created yet (the DoModal() method does it).

If I put my initialisation commands in the CMyDialog::OnInitDialog() function it works BUT this function is called each time the dialog is displayed so my changes are lost each time the dialog is displayed.
- How can I just iniitalise these controls ONCE when the program starts ?

- How can I create my second dialog once ? and then reuse it as long as the program lives ?

Thanks.
 
Add the initialization stuff to the constructor so you can do :

CMyDialog myDlg("Title","Blah blah blah", ...);

Matt

 
Thank you.
It almost works like I want it to.
In the "child" dialog box I have some checkboxes that I want enabling or disabling.
Unfortunately the EnableWindow(TRUE/FALSE) method fails for the same reasons.

Thanks for your advices.
-Philippe.
 
What you should do here is add some member variable to your dialog, such as

BOOL m_bCheckBoxEnabled

which you set to true or false (by passing an argument in the constructor, accessing the variable directly, whatever)

and add a Message Handler for WM_INITDIALOG. In the OnInitDialog function, enable or disable the check box using the value of m_bCheckBoxEnabled.

In short, this kind of control initialisation must be done after the window is created (e.g. in OnInitDialog)

Good luck

Vincent
 
Great !!
It works perfectly now.
Thank you very much
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top