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. How to destroy and delete a modeless Dialog

How to destroy and delete a modeless Dialog

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
8 Posts 5 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
    NorGUI
    wrote on last edited by
    #1

    Hello, I use this fonction to close and destroy a modeless dialogbox but it crash my application : m_Dlg* dialogbox CDialog created by new .. if (m_Dlg!=NULL) { m_Dlg->DestroyWindow(); delete m_Dlg; m_Dlg=NULL; } Should i use realy delete after destroy ? It works some time but it crash many time ! Thank you

    AutreChien

    T M P 3 Replies Last reply
    0
    • N NorGUI

      Hello, I use this fonction to close and destroy a modeless dialogbox but it crash my application : m_Dlg* dialogbox CDialog created by new .. if (m_Dlg!=NULL) { m_Dlg->DestroyWindow(); delete m_Dlg; m_Dlg=NULL; } Should i use realy delete after destroy ? It works some time but it crash many time ! Thank you

      AutreChien

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

      NorGUI wrote:

      f (m_Dlg!=NULL) { m_Dlg->DestroyWindow();

      Send WM_QUIT message before deleting the Dialog instead of DestroyWindow!, also check for existence of DialogWindow before cleaning up task!

      "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

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

      M M 2 Replies Last reply
      0
      • N NorGUI

        Hello, I use this fonction to close and destroy a modeless dialogbox but it crash my application : m_Dlg* dialogbox CDialog created by new .. if (m_Dlg!=NULL) { m_Dlg->DestroyWindow(); delete m_Dlg; m_Dlg=NULL; } Should i use realy delete after destroy ? It works some time but it crash many time ! Thank you

        AutreChien

        M Offline
        M Offline
        MayankT
        wrote on last edited by
        #3

        are you destroying window created by some other thread? in that case DestroyWindow will not work. Did it crash in DestroyWindow or delete?

        ---------------------- Mayank Thakore Learning C++ - since 1998 They didn't print my card right; so I resigned.

        N 1 Reply Last reply
        0
        • T ThatsAlok

          NorGUI wrote:

          f (m_Dlg!=NULL) { m_Dlg->DestroyWindow();

          Send WM_QUIT message before deleting the Dialog instead of DestroyWindow!, also check for existence of DialogWindow before cleaning up task!

          "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

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

          M Offline
          M Offline
          MayankT
          wrote on last edited by
          #4

          I'm new to VC++. WM_QUIT doc says it will quit app. Should we use it for one window?

          ---------------------- Mayank Thakore Learning C++ - since 1998 They didn't print my card right; so I resigned.

          T 1 Reply Last reply
          0
          • M MayankT

            I'm new to VC++. WM_QUIT doc says it will quit app. Should we use it for one window?

            ---------------------- Mayank Thakore Learning C++ - since 1998 They didn't print my card right; so I resigned.

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

            MayankT wrote:

            WM_QUIT doc says it will quit app

            A correction, it will stop message loop, not actually quit the window!. if you have put any wait function after the MessageLoop.. your window might get destroyed but your application still visible in running process list! have a look sample app! WinMain(....) {  ..........     GetMessage(&Msg,0,0,0)    {    }   .........  // WM_QUIT will break above loop but what about WaitForSingleObject written below!  WaitForSingleObject(...) }

            "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

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

            1 Reply Last reply
            0
            • N NorGUI

              Hello, I use this fonction to close and destroy a modeless dialogbox but it crash my application : m_Dlg* dialogbox CDialog created by new .. if (m_Dlg!=NULL) { m_Dlg->DestroyWindow(); delete m_Dlg; m_Dlg=NULL; } Should i use realy delete after destroy ? It works some time but it crash many time ! Thank you

              AutreChien

              P Offline
              P Offline
              prasad_som
              wrote on last edited by
              #6

              NorGUI wrote:

              if (m_Dlg!=NULL) { m_Dlg->DestroyWindow(); delete m_Dlg; m_Dlg=NULL; }

              There should not be any problem with this code. Can you tell, where crash taking you in the code. There must be something other , you are doing wrong.

              Prasad Notifier using ATL

              1 Reply Last reply
              0
              • M MayankT

                are you destroying window created by some other thread? in that case DestroyWindow will not work. Did it crash in DestroyWindow or delete?

                ---------------------- Mayank Thakore Learning C++ - since 1998 They didn't print my card right; so I resigned.

                N Offline
                N Offline
                NorGUI
                wrote on last edited by
                #7

                I found my problem it was that I called the from Parent Window dlg->DestroyWindow; and delete dlg; but in my class CDialog it was in void Dlg::PostNcDestroy() { CDialog::PostNcDestroy(); delete this; } thank you it was a big mistake from me

                AutreChien

                1 Reply Last reply
                0
                • T ThatsAlok

                  NorGUI wrote:

                  f (m_Dlg!=NULL) { m_Dlg->DestroyWindow();

                  Send WM_QUIT message before deleting the Dialog instead of DestroyWindow!, also check for existence of DialogWindow before cleaning up task!

                  "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

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

                  M Offline
                  M Offline
                  Michael Dunn
                  wrote on last edited by
                  #8

                  ? WM_QUIT is used with an app's main window. DestroyWindow() is the correct way to destroy a modeless dialog.

                  --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ

                  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