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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. closing a CDialog from the spawning parent

closing a CDialog from the spawning parent

Scheduled Pinned Locked Moved C / C++ / MFC
questionperformance
3 Posts 2 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.
  • N Offline
    N Offline
    nss
    wrote on last edited by
    #1

    Not quite sure about this. I create a modeless dialog in my MDI View class. Now at the click of a menu item I want this window to go away , and be completely gone from memory. If I just do a pMyDlg->ShowWindow(SW_HIDE) wont do away with it. SO how do I achieve this? I could delete the pointer after SW_HIDE but is that the way one does these things? Or should some message be sent to the CDialog?

    G 1 Reply Last reply
    0
    • N nss

      Not quite sure about this. I create a modeless dialog in my MDI View class. Now at the click of a menu item I want this window to go away , and be completely gone from memory. If I just do a pMyDlg->ShowWindow(SW_HIDE) wont do away with it. SO how do I achieve this? I could delete the pointer after SW_HIDE but is that the way one does these things? Or should some message be sent to the CDialog?

      G Offline
      G Offline
      Gary R Wheeler
      wrote on last edited by
      #2

      Use pMyDlg->DestroyWindow(). DestroyWindow() sends a WM_DESTROY message to the dialog, among other things. That's the legit way to close down a modeless dialog from 'outside' the dialog. Since you used a pointer, I'll assume somewhere you have code like:

      pMyDlg = new MyDlgClass(...);

      If that's the case, you will still need to do this:

      delete pMyDlg;

      somewhere. If you are doing this, you could have the MyDlgClass destructor call DestroyWindow(). With that, you could just do the delete pMyDlg, and the destructor would close down the dialog for you.


      Software Zen: delete this;

      N 1 Reply Last reply
      0
      • G Gary R Wheeler

        Use pMyDlg->DestroyWindow(). DestroyWindow() sends a WM_DESTROY message to the dialog, among other things. That's the legit way to close down a modeless dialog from 'outside' the dialog. Since you used a pointer, I'll assume somewhere you have code like:

        pMyDlg = new MyDlgClass(...);

        If that's the case, you will still need to do this:

        delete pMyDlg;

        somewhere. If you are doing this, you could have the MyDlgClass destructor call DestroyWindow(). With that, you could just do the delete pMyDlg, and the destructor would close down the dialog for you.


        Software Zen: delete this;

        N Offline
        N Offline
        nss
        wrote on last edited by
        #3

        Exactly what I nneded to know, esp calling DEstroyWindow() in the destructor....many thanks

        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