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

Modeless dialog

Scheduled Pinned Locked Moved C / C++ / MFC
help
6 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.
  • M Offline
    M Offline
    Mustafa Demirhan
    wrote on last edited by
    #1

    Hello, I have a big problem about modeless dialogs. When i create the dialog like CString msg("Message"); CShowMessage *swRem=new CShowMessage(msg); swRem->Create(IDD_SHOWMESSAGE_DIALOG); swRem->ShowWindow(SW_SHOW); it works fine.(This dialog gets a string as a parameter). However, if i call it like this CString msg("Message"); CShowMessage swRem(msg); swRem.Create(IDD_SHOWMESSAGE_DIALOG); swRem.ShowWindow(SW_SHOW); it appears first but then immediately dissappers. This is a big problem since i have to delete the new dialog if i use the first code. To delete this dialog, i pass the pointer of the dialog to itself as a parameter and the dialog deletes itself. However, this is not a good programming practice. I need your suggestions. Mustafa Demirhan

    R P S 3 Replies Last reply
    0
    • M Mustafa Demirhan

      Hello, I have a big problem about modeless dialogs. When i create the dialog like CString msg("Message"); CShowMessage *swRem=new CShowMessage(msg); swRem->Create(IDD_SHOWMESSAGE_DIALOG); swRem->ShowWindow(SW_SHOW); it works fine.(This dialog gets a string as a parameter). However, if i call it like this CString msg("Message"); CShowMessage swRem(msg); swRem.Create(IDD_SHOWMESSAGE_DIALOG); swRem.ShowWindow(SW_SHOW); it appears first but then immediately dissappers. This is a big problem since i have to delete the new dialog if i use the first code. To delete this dialog, i pass the pointer of the dialog to itself as a parameter and the dialog deletes itself. However, this is not a good programming practice. I need your suggestions. Mustafa Demirhan

      R Offline
      R Offline
      Remus Lazar
      wrote on last edited by
      #2

      Usually disapears because the scope of variable swRem is finished. The best way is the first solution and on WM_CLOSE message (should be more) try a "delete this" It should work. regards, /REMUS

      M 1 Reply Last reply
      0
      • M Mustafa Demirhan

        Hello, I have a big problem about modeless dialogs. When i create the dialog like CString msg("Message"); CShowMessage *swRem=new CShowMessage(msg); swRem->Create(IDD_SHOWMESSAGE_DIALOG); swRem->ShowWindow(SW_SHOW); it works fine.(This dialog gets a string as a parameter). However, if i call it like this CString msg("Message"); CShowMessage swRem(msg); swRem.Create(IDD_SHOWMESSAGE_DIALOG); swRem.ShowWindow(SW_SHOW); it appears first but then immediately dissappers. This is a big problem since i have to delete the new dialog if i use the first code. To delete this dialog, i pass the pointer of the dialog to itself as a parameter and the dialog deletes itself. However, this is not a good programming practice. I need your suggestions. Mustafa Demirhan

        P Offline
        P Offline
        Philip Nicoletti
        wrote on last edited by
        #3

        I suspect that your code : CString msg("Message"); CShowMessage swRem(msg); swRem.Create(IDD_SHOWMESSAGE_DIALOG); swRem.ShowWindow(SW_SHOW); is in some function. Once the function returns, static local variables are automattically destroyed. (in your case , msg and swRem). One thing to try is to make these variable global by putting the lines : CString msg("Message"); CShowMessage swRem(msg); at the top of your CPP file.

        S 1 Reply Last reply
        0
        • R Remus Lazar

          Usually disapears because the scope of variable swRem is finished. The best way is the first solution and on WM_CLOSE message (should be more) try a "delete this" It should work. regards, /REMUS

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

          Actually, the delete this; call should go in an override of PostNcDestroy().

          1 Reply Last reply
          0
          • P Philip Nicoletti

            I suspect that your code : CString msg("Message"); CShowMessage swRem(msg); swRem.Create(IDD_SHOWMESSAGE_DIALOG); swRem.ShowWindow(SW_SHOW); is in some function. Once the function returns, static local variables are automattically destroyed. (in your case , msg and swRem). One thing to try is to make these variable global by putting the lines : CString msg("Message"); CShowMessage swRem(msg); at the top of your CPP file.

            S Offline
            S Offline
            Sam Hobbs
            wrote on last edited by
            #5

            I assume that the CShowMessage constructor stores the parameter (msg) as a member variable for itself, so making it global is not necessary and would probably not accomplish anything even if it were global; the constructor does not use the variable, it uses the parameter. Also, C++ classes usually make it unnecessary to use global variables, so: CShowMessage swRem(msg); could be a member variable in the class where it is being used.

            1 Reply Last reply
            0
            • M Mustafa Demirhan

              Hello, I have a big problem about modeless dialogs. When i create the dialog like CString msg("Message"); CShowMessage *swRem=new CShowMessage(msg); swRem->Create(IDD_SHOWMESSAGE_DIALOG); swRem->ShowWindow(SW_SHOW); it works fine.(This dialog gets a string as a parameter). However, if i call it like this CString msg("Message"); CShowMessage swRem(msg); swRem.Create(IDD_SHOWMESSAGE_DIALOG); swRem.ShowWindow(SW_SHOW); it appears first but then immediately dissappers. This is a big problem since i have to delete the new dialog if i use the first code. To delete this dialog, i pass the pointer of the dialog to itself as a parameter and the dialog deletes itself. However, this is not a good programming practice. I need your suggestions. Mustafa Demirhan

              S Offline
              S Offline
              Sam Hobbs
              wrote on last edited by
              #6

              The documentation for modeless dialogs has been inadequate so I wrote some notes that might help people. See: http://home.socal.rr.com/samhobbs/VC/ModelessDialogs.html In that page I reference a MS KB article that was written after I wrote my notes.

              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