Search code examples
c++mfcsdi

MFC: How can I initialise CTabbedPane tabs (dialogs) using information from the Document in a SDI?


I'm fairly new to MFC and would like to create an SDI application that has a pane of tabs always embedded on the right of the window with a view left of it. In my app I have a calculation core, with variables that are changed in the tabs with edit boxes. I would like to initialise these variables in the calculation class and then during the initialisation of the dialogs used for tabs set the initial values in the edit boxes to those of the corresponding variable in the calculator.

Currently, I create an instance of the calculator in my document class. I also create a CTabbedPane in the MainFrame OnCreate Method as follows:

m_TabbedPane.Create(_T(""), this, CRect(0, 0, 290, 200),
    TRUE,
    (UINT)-1,
    WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS |
    WS_CLIPCHILDREN | CBRS_RIGHT |
    CBRS_FLOAT_MULTI))

m_tab = new CParametersDlg();
m_tab->Create(IDD_TAB, this);
m_TabbedPane.AddTab(m_tab);

I would the like to be able in CParameterDlg's OnInitDialog do something like:

BOOL CParameterDlg::OnInitDialog() {
CDialog::OnInitDialog()
float value = pointerToDocument->GetCalculatorVariable();

And use value to initialise an edit box. However I can't access the document from in the main frames OnCreate as it returns null (using GetActiveDocument, AfxGetApp etc).

How can I initialise the tabs then? I have thought about trying to put the Calculator in the App class instead. Or possibly trying to initialise the dialogs somewhere else which is called later when the document is properly initialised and linked? Or should I be doing things entirely differently?


Solution

  • I think that CMainFrame::OnCreate() is too early in the sequence of events to access the document class, it would not normally be created yet.

    It would be better to wait until the docuent is created / initialised, the document class could then call a new method in CMainFrame() passing this as a parameter to create the tabs.