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. modeless dialog and GetParent()

modeless dialog and GetParent()

Scheduled Pinned Locked Moved C / C++ / MFC
comquestion
14 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.
  • 2 23_444

    Sorry I dont' know what you mean. The dialog is created via clicking a button on a CFormView derived class and its pointer (this) is passed to the Modeless Dialog constructor.

    C Offline
    C Offline
    Chris Losinger
    wrote on last edited by
    #4

    a window's parent is set by the code that creates the window (in the case of a modeless dialog, that's generally your code). if you don't set a parent wnd (usually in the dlg ctor, or in Create) it will remain NULL. Cleek | Image Toolkits | Thumbnail maker

    2 1 Reply Last reply
    0
    • C Chris Losinger

      a window's parent is set by the code that creates the window (in the case of a modeless dialog, that's generally your code). if you don't set a parent wnd (usually in the dlg ctor, or in Create) it will remain NULL. Cleek | Image Toolkits | Thumbnail maker

      2 Offline
      2 Offline
      23_444
      wrote on last edited by
      #5

      Look at my first post. I am setting the parent window to the dialog. Please give me an example if I am off base.

      C 1 Reply Last reply
      0
      • 2 23_444

        Look at my first post. I am setting the parent window to the dialog. Please give me an example if I am off base.

        C Offline
        C Offline
        Chris Losinger
        wrote on last edited by
        #6

        ok. wasn't sure that was what that ctor was doing. are you calling Create anywhere ? Cleek | Image Toolkits | Thumbnail maker

        2 1 Reply Last reply
        0
        • C Chris Losinger

          ok. wasn't sure that was what that ctor was doing. are you calling Create anywhere ? Cleek | Image Toolkits | Thumbnail maker

          2 Offline
          2 Offline
          23_444
          wrote on last edited by
          #7

          Here is the code that creates the modeless dialog box void CFormsFormsFormsView::OnModelessheap() { if(m_pModeless){ m_pModeless->SetForegroundWindow(); m_pModeless->CenterWindow(); } else { m_pModeless = new CModelessDialogHeap(this); m_pModeless->Create(CModelessDialogHeap::IDD); m_pModeless->CenterWindow(); m_pModeless->ShowWindow(SW_SHOW); } } It all works fine. I just don't understand why GetParent() doesn't when called from the modeless dialog box. Thanks

          C 2 D 3 Replies Last reply
          0
          • 2 23_444

            Here is the code that creates the modeless dialog box void CFormsFormsFormsView::OnModelessheap() { if(m_pModeless){ m_pModeless->SetForegroundWindow(); m_pModeless->CenterWindow(); } else { m_pModeless = new CModelessDialogHeap(this); m_pModeless->Create(CModelessDialogHeap::IDD); m_pModeless->CenterWindow(); m_pModeless->ShowWindow(SW_SHOW); } } It all works fine. I just don't understand why GetParent() doesn't when called from the modeless dialog box. Thanks

            C Offline
            C Offline
            Chris Losinger
            wrote on last edited by
            #8

            can you step into that Create call ? i suspect some other bit of code somewhere is setting the dlg's m_pParentWnd to NULL. Create is another common place to set that variable. Cleek | Image Toolkits | Thumbnail maker

            1 Reply Last reply
            0
            • 2 23_444

              Here is the code that creates the modeless dialog box void CFormsFormsFormsView::OnModelessheap() { if(m_pModeless){ m_pModeless->SetForegroundWindow(); m_pModeless->CenterWindow(); } else { m_pModeless = new CModelessDialogHeap(this); m_pModeless->Create(CModelessDialogHeap::IDD); m_pModeless->CenterWindow(); m_pModeless->ShowWindow(SW_SHOW); } } It all works fine. I just don't understand why GetParent() doesn't when called from the modeless dialog box. Thanks

              2 Offline
              2 Offline
              23_444
              wrote on last edited by
              #9

              Yes I've stepped through the code. Like I said, the parent is passed into it just fine because I can assign that pointer to a member variable. But GetParent() should do the same thing...right? Appreciate your help. Here is the code CModelessDialogHeap::CModelessDialogHeap(CWnd* pParent /*=NULL*/) : CDialog(CModelessDialogHeap::IDD, pParent) { //{{AFX_DATA_INIT(CModelessDialogHeap) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT m_parent=pParent; }

              1 Reply Last reply
              0
              • 2 23_444

                I have created a modeless dialog. I am passing in the pointer to the parent window - which happens to be a CFormView derived class. m_pModeless = new CModelessDialogHeap(this); Now when I want to get the parent pointer (m_pModeless) from the modeless dialog I can do two things. A. Store the pointer passed into the constructor of the modeless dialog and use that -- which works. B. Or, according to one article on this site "http://thecodeproject.com/dialog/gettingmodeless.asp" I should be able to use GetParent(). When I do, it doesn't. It returns an empty pointer CWnd * tmpPtr = this->GetParent(); What am I missing? Thanks!

                D Offline
                D Offline
                David Crow
                wrote on last edited by
                #10

                I've tried this several different ways and it works fine each time (i.e., GetParent() returns the correct value). What does the constructor of CModelessDialogHeap look like? From where are you calling GetParent()? Is CModelessDialogHeap derived from CDialog?


                "One must learn from the bite of the fire to leave it alone." - Native American Proverb

                2 1 Reply Last reply
                0
                • 2 23_444

                  Here is the code that creates the modeless dialog box void CFormsFormsFormsView::OnModelessheap() { if(m_pModeless){ m_pModeless->SetForegroundWindow(); m_pModeless->CenterWindow(); } else { m_pModeless = new CModelessDialogHeap(this); m_pModeless->Create(CModelessDialogHeap::IDD); m_pModeless->CenterWindow(); m_pModeless->ShowWindow(SW_SHOW); } } It all works fine. I just don't understand why GetParent() doesn't when called from the modeless dialog box. Thanks

                  D Offline
                  D Offline
                  David Crow
                  wrote on last edited by
                  #11

                  mx483 wrote: m_pModeless->Create(CModelessDialogHeap::IDD); The only thing I do different for my modeless dialogs is to call Create(IDD) from within the dialog's constructor. Does commenting out the call to CenterWindow() have any effect?


                  "One must learn from the bite of the fire to leave it alone." - Native American Proverb

                  1 Reply Last reply
                  0
                  • D David Crow

                    I've tried this several different ways and it works fine each time (i.e., GetParent() returns the correct value). What does the constructor of CModelessDialogHeap look like? From where are you calling GetParent()? Is CModelessDialogHeap derived from CDialog?


                    "One must learn from the bite of the fire to leave it alone." - Native American Proverb

                    2 Offline
                    2 Offline
                    23_444
                    wrote on last edited by
                    #12

                    I sent the constructor of CModelessDialogHeap already. Here it is again. CModelessDialogHeap::CModelessDialogHeap(CWnd* pParent /*=NULL*/) : CDialog(CModelessDialogHeap::IDD, pParent) { //{{AFX_DATA_INIT(CModelessDialogHeap) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT m_parent=pParent; } CModelessDialogHeap is derived from CDialog. As long as the parent exists it shouldn't matter where GetParent is called. But I put a button on the dialog and attempted it while it was still active. void CModelessDialogHeap::OnButton1() { CWnd * tmpPtr = this->GetParent(); } Thanks for your help as well David.

                    D 1 Reply Last reply
                    0
                    • 2 23_444

                      I sent the constructor of CModelessDialogHeap already. Here it is again. CModelessDialogHeap::CModelessDialogHeap(CWnd* pParent /*=NULL*/) : CDialog(CModelessDialogHeap::IDD, pParent) { //{{AFX_DATA_INIT(CModelessDialogHeap) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT m_parent=pParent; } CModelessDialogHeap is derived from CDialog. As long as the parent exists it shouldn't matter where GetParent is called. But I put a button on the dialog and attempted it while it was still active. void CModelessDialogHeap::OnButton1() { CWnd * tmpPtr = this->GetParent(); } Thanks for your help as well David.

                      D Offline
                      D Offline
                      David Crow
                      wrote on last edited by
                      #13

                      At this point my suggestion would be to create a little dialog-based test application that does nothing but create and show a modeless dialog in the OnInitDialog() method. Let me know how that works out.


                      "One must learn from the bite of the fire to leave it alone." - Native American Proverb

                      2 1 Reply Last reply
                      0
                      • D David Crow

                        At this point my suggestion would be to create a little dialog-based test application that does nothing but create and show a modeless dialog in the OnInitDialog() method. Let me know how that works out.


                        "One must learn from the bite of the fire to leave it alone." - Native American Proverb

                        2 Offline
                        2 Offline
                        23_444
                        wrote on last edited by
                        #14

                        Okay I created a dialog based app and the GetParent function works as advertised. So now we know that the problem is more likely a conceptual one. The mainApp dialog is a popup and the CDialog derived modeless dialog is also a popup. Code is exactly the same as the problem project. In the problem project example I couldn't get to work I had an MDI application that had a CFormView derived class. It was a child. That child had a button when pressed would create the CDialog derived class modeless dialog. The CDialog derived class was set as PopUp. So can't a child spawn a modeless dialog (works) and can't that dialog in turn know it's spawning entity as Parent (GetParent). I won't mention anything about child as it was demonstrated to me by David that a modeless dialog shouldn't have a child style. I agree. I think this is important because these are pretty basic concepts. Thanks for your help.

                        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