Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. constructor and OnInitDialog()

constructor and OnInitDialog()

Scheduled Pinned Locked Moved C / C++ / MFC
c++tutorialquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    durban2
    wrote on last edited by
    #1

    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 ?

    S T 2 Replies Last reply
    0
    • D durban2

      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 ?

      S Offline
      S Offline
      Stuart Dootson
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • D durban2

        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 ?

        T Offline
        T Offline
        ThatsAlok
        wrote on last edited by
        #3

        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" - Mixture

        cheers, Alok Gupta VC Forum Q&A :- I/IV Support CRY- Child Relief and You

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups