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. a question?

a question?

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++
13 Posts 6 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 nenfa

    i create a popup dialog with mfc, and the dialog entered DoModal function, how can i close the dialog by pressing right-up close button and keep main-software keep going

    _ Offline
    _ Offline
    _Superman_
    wrote on last edited by
    #3

    Handle the WM_CLOSE message and in the handler, hide the dialog instead of calling DestroyWindow. This way the dialog is not shown anymore but the program is running.

    «_Superman_» I love work. It gives me something to do between weekends.
    Microsoft MVP (Visual C++)

    N 1 Reply Last reply
    0
    • N nenfa

      i create a popup dialog with mfc, and the dialog entered DoModal function, how can i close the dialog by pressing right-up close button and keep main-software keep going

      L Offline
      L Offline
      loyal ginger
      wrote on last edited by
      #4

      Since you said you called DoModal I assume you created a modal dialog box. When this dialog box is closed by clicking the top-right corner's close button, your application should still be running. You don't have to do anything to "keep it running". Clicking the close button should cause the DoModal to return the value IDCANCEL (and the dialog box being closed) unless you override the handler and do something else.

      N 1 Reply Last reply
      0
      • N nenfa

        i create a popup dialog with mfc, and the dialog entered DoModal function, how can i close the dialog by pressing right-up close button and keep main-software keep going

        N Offline
        N Offline
        neil kuo
        wrote on last edited by
        #5

        Try to overwirte the virtual function OnCancel(), and call EndDialog(n) in that. Or just call EndDialog(n) in OnClose() function.

        N 1 Reply Last reply
        0
        • 2 224917

          Your main application should not stop running if you close a pop-up dialog box that it created. Unless there is some kind of crash happening on the pop-up dialog box clean up.

          Suhredayan

          N Offline
          N Offline
          nenfa
          wrote on last edited by
          #6

          my application only have a dialog with some other win32 windows

          2 1 Reply Last reply
          0
          • _ _Superman_

            Handle the WM_CLOSE message and in the handler, hide the dialog instead of calling DestroyWindow. This way the dialog is not shown anymore but the program is running.

            «_Superman_» I love work. It gives me something to do between weekends.
            Microsoft MVP (Visual C++)

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

            i had tried, but it happened exception-error

            1 Reply Last reply
            0
            • L loyal ginger

              Since you said you called DoModal I assume you created a modal dialog box. When this dialog box is closed by clicking the top-right corner's close button, your application should still be running. You don't have to do anything to "keep it running". Clicking the close button should cause the DoModal to return the value IDCANCEL (and the dialog box being closed) unless you override the handler and do something else.

              N Offline
              N Offline
              nenfa
              wrote on last edited by
              #8

              maybe i make some wrong, if i closed the dialog box, it'll happen errors

              1 Reply Last reply
              0
              • N neil kuo

                Try to overwirte the virtual function OnCancel(), and call EndDialog(n) in that. Or just call EndDialog(n) in OnClose() function.

                N Offline
                N Offline
                nenfa
                wrote on last edited by
                #9

                i had tried, it all made errors

                1 Reply Last reply
                0
                • N nenfa

                  my application only have a dialog with some other win32 windows

                  2 Offline
                  2 Offline
                  224917
                  wrote on last edited by
                  #10

                  Can you post the code part that is creating the pop up dialog. Just to see how you are creating this pop-up dialog within your application.

                  Suhredayan

                  N 1 Reply Last reply
                  0
                  • 2 224917

                    Can you post the code part that is creating the pop up dialog. Just to see how you are creating this pop-up dialog within your application.

                    Suhredayan

                    N Offline
                    N Offline
                    nenfa
                    wrote on last edited by
                    #11

                    OK My CApp: InitInstance() { ... static CDlg dlg; m_pMainWnd = &dlg; //int nResponse = dlg.DoModal(); //if (nResponse == IDOK) // ... // dlg.Init(); return TRUE; } i create win32 window in dlg.Init() and its CallBackWnd code segment : case WM_COMMAND: { if (IDD_CONTROL_PANEL == wParam) { ((CDlg*)AfxGetApp()->GetMainWnd())->DoModal(); } }

                    L 1 Reply Last reply
                    0
                    • N nenfa

                      OK My CApp: InitInstance() { ... static CDlg dlg; m_pMainWnd = &dlg; //int nResponse = dlg.DoModal(); //if (nResponse == IDOK) // ... // dlg.Init(); return TRUE; } i create win32 window in dlg.Init() and its CallBackWnd code segment : case WM_COMMAND: { if (IDD_CONTROL_PANEL == wParam) { ((CDlg*)AfxGetApp()->GetMainWnd())->DoModal(); } }

                      L Offline
                      L Offline
                      Lost User
                      wrote on last edited by
                      #12

                      This looks to me like a Dialog application, where the dialog is the main window. So when the dialog closes that is the end of the application. If you want a normal window application that uses dialogs then create a proper framewindow as the main window. If you are using Visual Studio then there are standard framewindow templates to build from.

                      1 Reply Last reply
                      0
                      • N nenfa

                        i create a popup dialog with mfc, and the dialog entered DoModal function, how can i close the dialog by pressing right-up close button and keep main-software keep going

                        N Offline
                        N Offline
                        nenfa
                        wrote on last edited by
                        #13

                        thank you for everybody, i used modeless window in last.

                        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