Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ MFC
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)
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 21-Dec-12 3:59am
Edited 21-Dec-12 6:51am
v4
Comments
Jochen Arndt at 21-Dec-12 9:11am
   
You should show us the code portion from DialA where you create and show the DialB dialog.
Schehaider_Aymen at 21-Dec-12 9:27am
   
See answer 1 for my code
Jochen Arndt at 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.
Mohibur Rashid at 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.
ranjithkumar81 at 26-Dec-12 4:38am
   
Have you created modal dialog or modless dialog?
paste the pice of code here.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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.
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 230
1 PIEBALDconsult 150
2 DamithSL 125
3 Andreas Gieriet 90
4 Jochen Arndt 90
0 OriginalGriff 5,790
1 DamithSL 4,601
2 Maciej Los 4,012
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,195


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 7 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100