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. Accessing to parent view

Accessing to parent view

Scheduled Pinned Locked Moved C / C++ / MFC
c++question
5 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
    doctorpi
    wrote on last edited by
    #1

    Hi guys I've got an SDI app and from the view I call a dialog like this. In CMyView.cpp void CMyView::OpenMydialog() { CMyDialog dlg; dlg.SetFather(this); dlg.DoModal(); } and in my dialog I do this In MyDialog.h class CMyView; CMyView *m_pFather; void SetFather(CMyView *p_pFather); and in MyDialog.cpp #include "myappView.h" (but due to this I have to include first myappDoc.h") void CMyDialog::SetFather(CMyView *p_pFather) { m_pFather=p_pFather; } What's the usual (and right) way to acces the parent (View) class without to add all these includes? Now each time I compile , practically all app is compiled again and that's what I want to avoid. Thanks in forwarding Doc

    G T 2 Replies Last reply
    0
    • D doctorpi

      Hi guys I've got an SDI app and from the view I call a dialog like this. In CMyView.cpp void CMyView::OpenMydialog() { CMyDialog dlg; dlg.SetFather(this); dlg.DoModal(); } and in my dialog I do this In MyDialog.h class CMyView; CMyView *m_pFather; void SetFather(CMyView *p_pFather); and in MyDialog.cpp #include "myappView.h" (but due to this I have to include first myappDoc.h") void CMyDialog::SetFather(CMyView *p_pFather) { m_pFather=p_pFather; } What's the usual (and right) way to acces the parent (View) class without to add all these includes? Now each time I compile , practically all app is compiled again and that's what I want to avoid. Thanks in forwarding Doc

      G Offline
      G Offline
      GDavy
      wrote on last edited by
      #2

      void CMyView::OpenMydialog() { CMyDialog dlg(this); dlg.DoModal(); } //if you wonna get the parent in your dlg class void CMyDialog::AMethod() { //get the parent CWnd* pWnd = GetParent(); //you can also cast offcourse, but then you^ll need to include the MyView.h in the MyDialog.cpp: CMyView* pMyView = (CMyView*)GetParent(); } Hope this helps you, Greetings, Davy

      D 1 Reply Last reply
      0
      • G GDavy

        void CMyView::OpenMydialog() { CMyDialog dlg(this); dlg.DoModal(); } //if you wonna get the parent in your dlg class void CMyDialog::AMethod() { //get the parent CWnd* pWnd = GetParent(); //you can also cast offcourse, but then you^ll need to include the MyView.h in the MyDialog.cpp: CMyView* pMyView = (CMyView*)GetParent(); } Hope this helps you, Greetings, Davy

        D Offline
        D Offline
        doctorpi
        wrote on last edited by
        #3

        The problem is that if I follow your example I don't have access to the view variables. If I have a member called m_nCalls in my view How do I access to it? If I do CWnd* pWnd = GetParent(); pWnd->m_nCalls I receive compiling a nice error C2039: 'm_nCalls' : is not a member of 'CWnd' :( Doc

        G 1 Reply Last reply
        0
        • D doctorpi

          The problem is that if I follow your example I don't have access to the view variables. If I have a member called m_nCalls in my view How do I access to it? If I do CWnd* pWnd = GetParent(); pWnd->m_nCalls I receive compiling a nice error C2039: 'm_nCalls' : is not a member of 'CWnd' :( Doc

          G Offline
          G Offline
          GDavy
          wrote on last edited by
          #4

          If you want to access members of your view class you`ll need to cast.... CMyView *pMyView = (CMyView*)GetParent(); pMyView->m_nCalls = 2; don^t forget to do an #include "MyView.h" in your MyDialog.cpp file then.. Greetings, Davy

          1 Reply Last reply
          0
          • D doctorpi

            Hi guys I've got an SDI app and from the view I call a dialog like this. In CMyView.cpp void CMyView::OpenMydialog() { CMyDialog dlg; dlg.SetFather(this); dlg.DoModal(); } and in my dialog I do this In MyDialog.h class CMyView; CMyView *m_pFather; void SetFather(CMyView *p_pFather); and in MyDialog.cpp #include "myappView.h" (but due to this I have to include first myappDoc.h") void CMyDialog::SetFather(CMyView *p_pFather) { m_pFather=p_pFather; } What's the usual (and right) way to acces the parent (View) class without to add all these includes? Now each time I compile , practically all app is compiled again and that's what I want to avoid. Thanks in forwarding Doc

            T Offline
            T Offline
            Tom Archer
            wrote on last edited by
            #5

            Another - more "correct" object oriented method - would be to pass the view's pointer to the dialog's constructor (as another poster pointed out). Then when the dialog needs to communicate with the view it would do so via messaging as opposed to directly accessing the view's members, which is an obvious OOP no-no Cheers, Tom Archer - Archer Consulting Group
            "Eat your brussel sprouts, Junior. There are starving Chinese children American programmers that would kill for that food!"

            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