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. Dialog is getting close automatically

Dialog is getting close automatically

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

    Hi, We have SDI application. In which we are opening some dialogs. Once application is up these dialogs can be open and close as many times as possible. If I am opening dialog first time, minimize application(not dialog, i mean whole application) and then maximize application, dialog is also displayed in previous condition. But if i close and open dialog again, on minimize and maximize application make dialog disappear, I have to open dialog explicitly. How can I stop this behavior? I tried to explain situation as much as possible. If anyone have doubt fire your question. Thanks.

    A 1 Reply Last reply
    0
    • C chevu

      Hi, We have SDI application. In which we are opening some dialogs. Once application is up these dialogs can be open and close as many times as possible. If I am opening dialog first time, minimize application(not dialog, i mean whole application) and then maximize application, dialog is also displayed in previous condition. But if i close and open dialog again, on minimize and maximize application make dialog disappear, I have to open dialog explicitly. How can I stop this behavior? I tried to explain situation as much as possible. If anyone have doubt fire your question. Thanks.

      A Offline
      A Offline
      Avi Berger
      wrote on last edited by
      #2

      I don't know. Two questions do immediately come to my mind, so I will share them in case they lead you somewhere. Are you consistently setting the parent window everywhere you are creating/recreating the dialogs? (Presuming you are using MFC) How are you managing the lifetime of CDialog derived object associated with the dialog? I hope these might lead you somewhere, but I don't know if they will.

      C 1 Reply Last reply
      0
      • A Avi Berger

        I don't know. Two questions do immediately come to my mind, so I will share them in case they lead you somewhere. Are you consistently setting the parent window everywhere you are creating/recreating the dialogs? (Presuming you are using MFC) How are you managing the lifetime of CDialog derived object associated with the dialog? I hope these might lead you somewhere, but I don't know if they will.

        C Offline
        C Offline
        chevu
        wrote on last edited by
        #3

        First thing, I am not recreating dialog every time. I mean Once it is created i am not destroying its handle/object till application is down. So setting of parent is done once. I think this will be ans or your second que also. And ya I am using MFC.

        A 1 Reply Last reply
        0
        • C chevu

          First thing, I am not recreating dialog every time. I mean Once it is created i am not destroying its handle/object till application is down. So setting of parent is done once. I think this will be ans or your second que also. And ya I am using MFC.

          A Offline
          A Offline
          Avi Berger
          wrote on last edited by
          #4

          Well, that sounds right. So you will be intercepting user request to close the dialog and hiding it instead. Something has to have changed in the state of the dialog or object, but I'm afraid I'm not going to come up with it. My remaining thought is to monitor the windows messages being sent to the dialog in the 2 situations. A difference would obviously be a clue. Failing that, it might suggest a good point to put in a breakpoint. Good Luck.

          C 1 Reply Last reply
          0
          • A Avi Berger

            Well, that sounds right. So you will be intercepting user request to close the dialog and hiding it instead. Something has to have changed in the state of the dialog or object, but I'm afraid I'm not going to come up with it. My remaining thought is to monitor the windows messages being sent to the dialog in the 2 situations. A difference would obviously be a clue. Failing that, it might suggest a good point to put in a breakpoint. Good Luck.

            C Offline
            C Offline
            chevu
            wrote on last edited by
            #5

            No I am not stoping dialog from being close check this part;

            void CHWSimulatorDlg::OnSysCommand(UINT nID, LPARAM lParam)
            {
            switch(nID)
            {
            //Event for maximize HWsimulator window
            case SC_MAXIMIZE:
            ShowWindow(SW_SHOWMAXIMIZED);
            bMaximizeFlag = true; //Seting flag
            break;

            //Event for restore or close window
            case SC\_RESTORE:
            case SC\_CLOSE:
            	bMaximizeFlag = false;	//Reset the flag
            	CDialog::OnSysCommand(nID, lParam);
            	break;
            
            default:
            	CDialog::OnSysCommand(nID, lParam);
            	break;
            
            }
            

            }

            I tried to debug this part, I am not getting any message in this function when I am minimizing whole application. And I havnt override OnClose function for this dialog.

            A 1 Reply Last reply
            0
            • C chevu

              No I am not stoping dialog from being close check this part;

              void CHWSimulatorDlg::OnSysCommand(UINT nID, LPARAM lParam)
              {
              switch(nID)
              {
              //Event for maximize HWsimulator window
              case SC_MAXIMIZE:
              ShowWindow(SW_SHOWMAXIMIZED);
              bMaximizeFlag = true; //Seting flag
              break;

              //Event for restore or close window
              case SC\_RESTORE:
              case SC\_CLOSE:
              	bMaximizeFlag = false;	//Reset the flag
              	CDialog::OnSysCommand(nID, lParam);
              	break;
              
              default:
              	CDialog::OnSysCommand(nID, lParam);
              	break;
              
              }
              

              }

              I tried to debug this part, I am not getting any message in this function when I am minimizing whole application. And I havnt override OnClose function for this dialog.

              A Offline
              A Offline
              Avi Berger
              wrote on last edited by
              #6

              I don't think that the code you posted is the problem. It also doesn't seem that useful to me.

              Now chevu wrote:

              No I am not stoping dialog from being close

              Combined with other things that you have said, this suggests to me that we may actually be getting somewhere. First, I'll explicitly state my understanding that we are discussing modeless dialog boxes with associated classes derived from CDialog. Now let me try to quickly summarize lots of stuff. Some of this may seem to simple to mention. I'm doing it anyway because I suspect that you are missing part of this, but I don't know what part. In working with modeless dialog boxes in MFC there are 2 things around that one has to worry about. One is a C++ object instantiated from a class derived from CDialog. This is normally dynamically allocated so that its lifetime can be properly managed. The other is the windows object (not a C++ object) that Windows maintains and deals with that a windows handle is connected to. They are associated, but they are somewhat independent things. A class for a modeless dialog overrides OnOK and OnCancel and does NOT call the default versions. The default ones in CDialog call EndDialog() which is intended for use with modal, not modeless dialogs. (I'm not sure of all the implications of calling it for a modeless dialog, but I suspect this may be a part of your situation.) These overrides might call DestroyWindow() to terminate the dialog and kill the windows object. When it is desired that the dynamically allocated C++ object self-destructs when the dialog is closed, PostNcDestroy() is also overriden. Typically, one constructs the C++ object and calls Create() which creates and associates the windows object. Later, the user exits the dialog in some way. The programmer has provided code for this that includes a call to DestroyWindow(). Then some programmer provided mechanism deletes the C++ object. Now you want to do things differently. Once things are created, you want to keep things around (though not necessarily displayed) until the program exits. So when the user "closes" the dialog instead of destroying the window object (via DestroyWindow) and deleting the C++ object, you are writing code to hide the window and keep track that you have done this. Then when you want to display the dialog again you would just show the window. It now sounds like this isn't what you are actually doing. Perhaps you are letting EndDialog() be called. I don't kn

              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