Click here to Skip to main content
13,189,324 members (68,838 online)
Rate this:
Please Sign up or sign in to vote.
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)
BOOL CDialB::OnInitDialog()
    return TRUE;  // return TRUE unless you set the focus to a control
    // EXCEPTION: OCX Property Pages should return FALSE
Posted 21-Dec-12 2:59am
Updated 21-Dec-12 5:51am
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

Use the green 'Improve question' link to edit your question and add additional information like code snippets. Afterwards, delete the solution.
sajeesh.c 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.
ranjithkumar81 26-Dec-12 4:38am
Have you created modal dialog or modless dialog?
paste the pice of code here.
Rate this: bad
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.
Rate this: bad
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.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.171016.2 | Last Updated 7 Mar 2013
Copyright © CodeProject, 1999-2017
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