constructor and OnInitDialog()
-
MFC, STUDIO 2008, MDI Why ignore ( skip ) value from OnInitDialog() There are modal and modeless windows: // modeldlg2.h class CMainDlg2 : public CDialog // modal window { public: virtual BOOL OnInitDialog(); CString m_sPP_modal7; }; // adderdlg2.h class CAdderDialog2 : public Cdialog // modeless window { public: virtual BOOL OnInitDialog(); }; // modeldlg2.cpp : implementation file CMainDlg2::CMainDlg2(CWnd* pParent /*=NULL*/) // standard constructor : CDialog(CMainDlg2::IDD, pParent) m_sPP_modal7 = "Paris"; } BOOL CMainDlg2::OnInitDialog() { CDialog::OnInitDialog(); m_sPP_modal7 = "New-York"; return TRUE; // return TRUE unless you set the focus to a control } // adderdlg2.cpp : implementation file MODELESS window BOOL CAdderDialog2::OnInitDialog() { CDialog::OnInitDialog(); CMainDlg2 dlg7; MessageBox(L"dlg7.m_sPP_modal7 = \n" + dlg7.m_sPP_modal7); Why have been chose value from constructor but not from the method OnInitDialog() modal window? } Result: Paris Why not New-York ? How to receive New-York ?
-
MFC, STUDIO 2008, MDI Why ignore ( skip ) value from OnInitDialog() There are modal and modeless windows: // modeldlg2.h class CMainDlg2 : public CDialog // modal window { public: virtual BOOL OnInitDialog(); CString m_sPP_modal7; }; // adderdlg2.h class CAdderDialog2 : public Cdialog // modeless window { public: virtual BOOL OnInitDialog(); }; // modeldlg2.cpp : implementation file CMainDlg2::CMainDlg2(CWnd* pParent /*=NULL*/) // standard constructor : CDialog(CMainDlg2::IDD, pParent) m_sPP_modal7 = "Paris"; } BOOL CMainDlg2::OnInitDialog() { CDialog::OnInitDialog(); m_sPP_modal7 = "New-York"; return TRUE; // return TRUE unless you set the focus to a control } // adderdlg2.cpp : implementation file MODELESS window BOOL CAdderDialog2::OnInitDialog() { CDialog::OnInitDialog(); CMainDlg2 dlg7; MessageBox(L"dlg7.m_sPP_modal7 = \n" + dlg7.m_sPP_modal7); Why have been chose value from constructor but not from the method OnInitDialog() modal window? } Result: Paris Why not New-York ? How to receive New-York ?
durban2 wrote:
Why not New-York ?
Because the dlg7 member hasn't been created as a window yet, so hasn't received WM_INITDIALOG yet. You may have noticed that you haven't seen that dialog at all?
durban2 wrote:
How to receive New-York ?
You need to get a WM_INITDIALOG sent to your dialog. Which means showing it. Which menas that as it's a modal dialog, you need to call dlg7.DoModal() before the MessageBox call.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
-
MFC, STUDIO 2008, MDI Why ignore ( skip ) value from OnInitDialog() There are modal and modeless windows: // modeldlg2.h class CMainDlg2 : public CDialog // modal window { public: virtual BOOL OnInitDialog(); CString m_sPP_modal7; }; // adderdlg2.h class CAdderDialog2 : public Cdialog // modeless window { public: virtual BOOL OnInitDialog(); }; // modeldlg2.cpp : implementation file CMainDlg2::CMainDlg2(CWnd* pParent /*=NULL*/) // standard constructor : CDialog(CMainDlg2::IDD, pParent) m_sPP_modal7 = "Paris"; } BOOL CMainDlg2::OnInitDialog() { CDialog::OnInitDialog(); m_sPP_modal7 = "New-York"; return TRUE; // return TRUE unless you set the focus to a control } // adderdlg2.cpp : implementation file MODELESS window BOOL CAdderDialog2::OnInitDialog() { CDialog::OnInitDialog(); CMainDlg2 dlg7; MessageBox(L"dlg7.m_sPP_modal7 = \n" + dlg7.m_sPP_modal7); Why have been chose value from constructor but not from the method OnInitDialog() modal window? } Result: Paris Why not New-York ? How to receive New-York ?
durban2 wrote:
Why have been chose value from constructor but not from the method OnInitDialog() modal window?
because, OnInitDialog for dlg7 is not called yet, it only call once Dialog is created!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
Never mind - my own stupidity is the source of every "problem" - Mixturecheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You