Click here to Skip to main content
15,887,267 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello all,

in my Appliation I have 2 Dialogs : DialA and DialB

In The DialB::OnInitDialog() I Have some parameters intialization like SetLimitText etc ...

When I call DialB via DialA (by pressing a buttom) the preparameters set on the DialB::OninitDialog() does work. But when i Call DialB from The Menu All works fine.

i even trie to go step by step via debug mode but the prog don't go the breakpoints when i Call DialB via DialA.

What is Wrong ? I need that the DilB:OnInitDialog Works for both. Help Plz

Code of CDialB (copied from OP non-solution)
C++
BOOL CDialB::OnInitDialog()
{
    CDialog::OnInitDialog();
    m_Edit_TRIMESTRECTR.SetLimitText(3);
    UpdateData(TRUE);
 
    return TRUE;  // return TRUE unless you set the focus to a control
    // EXCEPTION: OCX Property Pages should return FALSE
}
Posted
Updated 21-Dec-12 5:51am
v4
Comments
Jochen Arndt 21-Dec-12 9:11am    
You should show us the code portion from DialA where you create and show the DialB dialog.
Schehaider_Aymen 21-Dec-12 9:27am    
See answer 1 for my code
Jochen Arndt 21-Dec-12 9:32am    
NO!

Use the green 'Improve question' link to edit your question and add additional information like code snippets. Afterwards, delete the solution.
[no name] 22-Dec-12 1:40am    
You should provide some additional information. Otherwise we can't detect the problem
Mohibur Rashid 22-Dec-12 2:17am    
I don't even call CDialog::OnInitDialog(); in my function but that is not the problem.


Now, Make sure you have done your CDialB() construction properly. with proper id.

OnInitDialog() is only called once, so if it was already called, it will not be called again. There are better ways to do something every time a dialog is displayed or opened.
 
Share this answer
 
OnInitDialog() is only called when the dialog is first created and meant to load default values of GUI components (and anything else you need to do AFTER the dialog components have been created but BEFORE the regular operation of the dialog).... with that said, if you need to set something EVERY time you bring up the dialog.

CEdit::SetLimitText() only needs to be called once during the existance of a dialog and the CEdit control, therefore it is appropriate that it's called in the method OnInitDialog(), however, there really should be no reason for you to continually set it.

When you make a CDialog you can do it in two ways, make it once at the beginning of the application execution and just bring it up when you need it (appropriate for something you'll constantly use) or you can just make it and delete it every time you're going to use it (appropriate when memory usage is at a premium, but heap allocations can be relatively slow so keep that in mind). The simple way is to just make the dialog off the back and bring it up when you need it, in that case, OnInitDialog() will only be called once during the entire app execution.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900