Hi,
I need to be able to dynamically initialize 2 dialogs (1 parent dlg and 1 modal child dlg). As far as I understand it I need to overload an OnInitDialog for each.
The problem however is that since OnInitDialog is and must be a virtual function, the child dialog fails to call my overloaded OnInitDialog.
wow my terminology is lacking.
I meant override.
Thanks for your patience...
It looks like this in both dialog's headers: virtual BOOL OnInitDialog();
Then the .cpp of both look like this :
1 2 3 4 5 6 7 8 9
BOOL CResultsDlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
// TODO: Add extra initialization here
m_hResult.SendMessageA(WM_SETTEXT, 0, (LPARAM)"print result!"); //in child dialog
returntrue; // return TRUE unless you set the focus to a control
}
and
1 2 3 4 5 6 7 8 9
BOOL CCalculator::OnInitDialog()
{
CDialogEx::OnInitDialog();
// TODO: Add extra initialization here
m_hCalc.SendMessageA(WM_SETTEXT, 0, (LPARAM)"print me!"); //in parent dialog
returntrue; // return TRUE unless you set the focus to a control
}
Ideally I'd like to overload the constructors (this time I do mean overload) to pass a value from the parent to the child but the overridden OnInitDialog isn't called in the child if I do that (breakpoints told me that)...
The problem however is that since OnInitDialog is and must be a virtual function, the child dialog fails to call my [overridden] OnInitDialog.
soranz wrote:
[...] but the overridden OnInitDialog isn't called in the child if I do that
I'm confused, there's three OnInitDialog functions here. I'm going to number them:
1. CResultsDlg::OnInitDialog()
2. CCalculator::OnInitDialog()
3. CDialogEx::OnInitDialog()
Which ones are you referring to, and when? Could you be more clear? Sorry for not understanding.
When the program starts 'CCalculator::OnInitDialog()' is called to set values the moment before the dialog box is displayed to the user. This is the main dialog.
Once the user presses a 'Results' button on the main dialog, I handle the event by creating another dialog box which I want to pass a value from the parent to, which looks like this:
None of this version or an overloaded constructor or an overloaded DoModal end up calling CResultsDlg::OnInitDialog() :*(
According to MSDN:
Override this method if you want to perform special processing when the dialog box is initialized. In the overridden version, first call the base class OnInitDialog but ignore its return value.
That's what I tried to do but I'm unclear of how it all works...
That's exactly what I tried to do and they are indeed stored as member variables of the CResultsDlg object !
But I don't know how to initialize them at the dialog's creation. I thought that I am supposed to pass them into the constructor and then override CResultsDlg::OnInitDialog() to send messages to the 'results' static text controls to display those passed values.
The only workarounds I can think of is to either have a separate button in CResultsDlg for the user to click to actually show the result (inconvenient to user)
*or*
Use the MessageBox() function which would work...but it has limited customization and would look messy...
I have no experience with MFC, so at this point I have done as much as I can to help you. Hopefully someone who is familiar with MFC will come along...