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. Modal dialog - Close - ESC

Modal dialog - Close - ESC

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
37 Posts 10 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.
  • P Prakash Nadar

    PreTranslateMessage is good but did you consider http://www.codeproject.com/script/comments/forums.asp?msg=1338886&forumid=1647#xx1338886xx[^]


    -Prakash

    T Offline
    T Offline
    toxcct
    wrote on last edited by
    #18

    much better, and very simple !!! thanks to mickael...


    TOXCCT >>> GEII power
    [toxcct][VisualCalc 2.20][VCalc 3.0 soon...]

    P R 2 Replies Last reply
    0
    • T toxcct

      much better, and very simple !!! thanks to mickael...


      TOXCCT >>> GEII power
      [toxcct][VisualCalc 2.20][VCalc 3.0 soon...]

      P Offline
      P Offline
      Prakash Nadar
      wrote on last edited by
      #19

      toxcct wrote:

      thanks to mickael...

      no doubt. :)


      -Prakash

      1 Reply Last reply
      0
      • P Prakash Nadar

        PreTranslateMessage is good but did you consider http://www.codeproject.com/script/comments/forums.asp?msg=1338886&forumid=1647#xx1338886xx[^]


        -Prakash

        S Offline
        S Offline
        Stephen Hewitt
        wrote on last edited by
        #20

        That approach seemed to stop the dialog box from begin closed by any means so I ruled it out. I don't actually remember him saying he uses MFC, but that seems to be assumed in this forum. I try to steer clear of MFC in my own projects although I use it extensively at work. The MFC source code is a valuable resource however. Steve

        P 1 Reply Last reply
        0
        • S Stephen Hewitt

          That approach seemed to stop the dialog box from begin closed by any means so I ruled it out. I don't actually remember him saying he uses MFC, but that seems to be assumed in this forum. I try to steer clear of MFC in my own projects although I use it extensively at work. The MFC source code is a valuable resource however. Steve

          P Offline
          P Offline
          Prakash Nadar
          wrote on last edited by
          #21

          Stephen Hewitt wrote:

          That approach seemed to stop the dialog box from begin closed by any means so I ruled it out.

          you dont put for both onok and oncancel, just the oncancel will do in this case.


          -Prakash

          S R 2 Replies Last reply
          0
          • P Prakash Nadar

            Stephen Hewitt wrote:

            That approach seemed to stop the dialog box from begin closed by any means so I ruled it out.

            you dont put for both onok and oncancel, just the oncancel will do in this case.


            -Prakash

            S Offline
            S Offline
            Stephen Hewitt
            wrote on last edited by
            #22

            When I test just OnCancel and stopped it calling CDialog::OnCancel the dialog can't be closed by any means other the pressing "OK". This includes the "x", the system menu and escape. Steve

            1 Reply Last reply
            0
            • P Prakash Nadar

              Stephen Hewitt wrote:

              That approach seemed to stop the dialog box from begin closed by any means so I ruled it out.

              you dont put for both onok and oncancel, just the oncancel will do in this case.


              -Prakash

              R Offline
              R Offline
              Rajesh R Subramanian
              wrote on last edited by
              #23

              I knew this other solution well before I had posted the PreTranslateMessage handling solution. But it will just change the functionality of OnCancel() too. If i write my code in OnCancel(), not to close, then on clicking the cancel button too, the dialog won't close. Don't tell me you did not know this please. I might want to do something else on OnOk() too. Handling the pretranslatemessage is not a big job. And its powerful than any other way when you work with MFC. I cannot think of any other easier and powerful way to do this. If you know something else which is REALLY APPROPRIATE and RELEVANT, please let us know too. Thanks in advance. Regards, Rajesh R. Subramanian You have an apple and me too. We exchange those and We have an apple each. You have an idea and me too. We exchange those and We have two ideas each.

              P 1 Reply Last reply
              0
              • T toxcct

                much better, and very simple !!! thanks to mickael...


                TOXCCT >>> GEII power
                [toxcct][VisualCalc 2.20][VCalc 3.0 soon...]

                R Offline
                R Offline
                Rajesh R Subramanian
                wrote on last edited by
                #24

                Tox, how is it much better? Do I write in thin air? If i edit OnCancel(), then will it not change the whole good functionality of the button? I accept, I edit the OnCancel() and the dialog won't close on pressing the Escape then what about clicking the cancel button dude? Don't tell me you did not know this. Please explain tox. I knew mike's solution already and still I think PreTranslateMessage is best. Regards, Rajesh R. Subramanian You have an apple and me too. We exchange those and We have an apple each. You have an idea and me too. We exchange those and We have two ideas each.

                1 Reply Last reply
                0
                • M Michael Dunn

                  See the FAQ 7.4 How do I prevent a dialog from closing when the user presses Enter or Esc?[^] --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ Shots do not hurt other players... yet

                  R Offline
                  R Offline
                  Rajesh R Subramanian
                  wrote on last edited by
                  #25

                  Hi Mike, Is handling the PreTranslateMessage() better or the one which you have given is better? How? My opinion is that when you write code inside the OnCancel() it will modify the functionality of the cancel button (and the close button of the window) too! Which in turn will stop the dialog from closing somehow.. Should another button be added to close then? Is this approach right? I am asking because I am a big fan of you and I need the reason behind your approach in this matter. Regards, Rajesh R. Subramanian You have an apple and me too. We exchange those and We have an apple each. You have an idea and me too. We exchange those and We have two ideas each.

                  M 1 Reply Last reply
                  0
                  • R Rajesh R Subramanian

                    I knew this other solution well before I had posted the PreTranslateMessage handling solution. But it will just change the functionality of OnCancel() too. If i write my code in OnCancel(), not to close, then on clicking the cancel button too, the dialog won't close. Don't tell me you did not know this please. I might want to do something else on OnOk() too. Handling the pretranslatemessage is not a big job. And its powerful than any other way when you work with MFC. I cannot think of any other easier and powerful way to do this. If you know something else which is REALLY APPROPRIATE and RELEVANT, please let us know too. Thanks in advance. Regards, Rajesh R. Subramanian You have an apple and me too. We exchange those and We have an apple each. You have an idea and me too. We exchange those and We have two ideas each.

                    P Offline
                    P Offline
                    Prakash Nadar
                    wrote on last edited by
                    #26

                    it all depended on the design on the dialog box. Instead of traditional IDCANCEL a different id say ID_CANCEL button can be added to the dialog which could call the baseclass OnCancel to cancel the dialog. from your reply you look like pissed off, just chill baby.


                    -Prakash

                    C S 2 Replies Last reply
                    0
                    • P Prakash Nadar

                      it all depended on the design on the dialog box. Instead of traditional IDCANCEL a different id say ID_CANCEL button can be added to the dialog which could call the baseclass OnCancel to cancel the dialog. from your reply you look like pissed off, just chill baby.


                      -Prakash

                      C Offline
                      C Offline
                      color Aljechin
                      wrote on last edited by
                      #27

                      Huh? I am not pissed or anything. I think its absolutely waste to rename ID_CANCEL and then write code inside that oncancel function and all. If it is Just for the sake to argue, you can continue to rename everything and modify functions. Its that you know what it is and still you want to rename something and then edit existing functionality or add a button separately to close,,,..... Phew! I am tired. I will continue to use Pretranslatemsg.

                      R P 2 Replies Last reply
                      0
                      • C color Aljechin

                        Huh? I am not pissed or anything. I think its absolutely waste to rename ID_CANCEL and then write code inside that oncancel function and all. If it is Just for the sake to argue, you can continue to rename everything and modify functions. Its that you know what it is and still you want to rename something and then edit existing functionality or add a button separately to close,,,..... Phew! I am tired. I will continue to use Pretranslatemsg.

                        R Offline
                        R Offline
                        Rajesh R Subramanian
                        wrote on last edited by
                        #28

                        :confused: Prakash is talking to me. What is ur problem You have an apple and me too. We exchange those and We have an apple each. You have an idea and me too. We exchange those and We have two ideas each.

                        C 1 Reply Last reply
                        0
                        • R Rajesh R Subramanian

                          :confused: Prakash is talking to me. What is ur problem You have an apple and me too. We exchange those and We have an apple each. You have an idea and me too. We exchange those and We have two ideas each.

                          C Offline
                          C Offline
                          color Aljechin
                          wrote on last edited by
                          #29

                          i had been reading this thread. i thought PreTranslateMessage() is better. i always use that only. he told anybody using PreTranslateMessage() is pissed. so i replied.

                          P 1 Reply Last reply
                          0
                          • C color Aljechin

                            Huh? I am not pissed or anything. I think its absolutely waste to rename ID_CANCEL and then write code inside that oncancel function and all. If it is Just for the sake to argue, you can continue to rename everything and modify functions. Its that you know what it is and still you want to rename something and then edit existing functionality or add a button separately to close,,,..... Phew! I am tired. I will continue to use Pretranslatemsg.

                            P Offline
                            P Offline
                            Prakash Nadar
                            wrote on last edited by
                            #30

                            wow, cool down, i didnt say using pretranslate message is a bad way of using it, Like I said it would all depend on the design of the dialog.


                            -Prakash

                            1 Reply Last reply
                            0
                            • C color Aljechin

                              i had been reading this thread. i thought PreTranslateMessage() is better. i always use that only. he told anybody using PreTranslateMessage() is pissed. so i replied.

                              P Offline
                              P Offline
                              Prakash Nadar
                              wrote on last edited by
                              #31

                              Aljechin he told anybody using PreTranslateMessage() is pissed.

                              talk about misinterpretation. ;)


                              -Prakash

                              1 Reply Last reply
                              0
                              • P Prakash Nadar

                                it all depended on the design on the dialog box. Instead of traditional IDCANCEL a different id say ID_CANCEL button can be added to the dialog which could call the baseclass OnCancel to cancel the dialog. from your reply you look like pissed off, just chill baby.


                                -Prakash

                                S Offline
                                S Offline
                                Stephen Hewitt
                                wrote on last edited by
                                #32

                                Yeah, but the "x" button and the system menu close functions don't work then. Steve

                                R 1 Reply Last reply
                                0
                                • S Stephen Hewitt

                                  Yeah, but the "x" button and the system menu close functions don't work then. Steve

                                  R Offline
                                  R Offline
                                  Rajesh R Subramanian
                                  wrote on last edited by
                                  #33

                                  Exactly! That is what I am talking about and trying to explain, but he is talking something else. Either he is not understanding what we tell or he does not know it or he understands it, but just wants to argue. Leave him there. Regards, Rajesh R. Subramanian You have an apple and me too. We exchange those and We have an apple each. You have an idea and me too. We exchange those and We have two ideas each.

                                  1 Reply Last reply
                                  0
                                  • R Rajesh R Subramanian

                                    Hi Mike, Is handling the PreTranslateMessage() better or the one which you have given is better? How? My opinion is that when you write code inside the OnCancel() it will modify the functionality of the cancel button (and the close button of the window) too! Which in turn will stop the dialog from closing somehow.. Should another button be added to close then? Is this approach right? I am asking because I am a big fan of you and I need the reason behind your approach in this matter. Regards, Rajesh R. Subramanian You have an apple and me too. We exchange those and We have an apple each. You have an idea and me too. We exchange those and We have two ideas each.

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

                                    In general, the higher-up the call stack that you can make a change, the better. Doing it on OnCancel() is as high up as you can go. The reasoning being, the higher-up layers are less likely to change between versions of MFC (thus breaking your code), and higher-up changes are easier for others to maintain. PreTranslateMessage() deals with the raw messages, you may perhaps run into weird cases regarding key states, shift states, and so on. --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ

                                    P R 2 Replies Last reply
                                    0
                                    • M Michael Dunn

                                      In general, the higher-up the call stack that you can make a change, the better. Doing it on OnCancel() is as high up as you can go. The reasoning being, the higher-up layers are less likely to change between versions of MFC (thus breaking your code), and higher-up changes are easier for others to maintain. PreTranslateMessage() deals with the raw messages, you may perhaps run into weird cases regarding key states, shift states, and so on. --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ

                                      P Offline
                                      P Offline
                                      Prakash Nadar
                                      wrote on last edited by
                                      #35

                                      Hey Michael, Is there a way to identify how OnCancel message was called? i.e. by clicking on the button or pressing the ESC key. thanks


                                      -Prakash

                                      M 1 Reply Last reply
                                      0
                                      • P Prakash Nadar

                                        Hey Michael, Is there a way to identify how OnCancel message was called? i.e. by clicking on the button or pressing the ESC key. thanks


                                        -Prakash

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

                                        I've never had to do this myself, but if there is a difference, it would be in the WM_COMMAND parameters - you could compare what wParam and lParam are in those two cases, and then you'd know what you check for. --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ

                                        1 Reply Last reply
                                        0
                                        • M Michael Dunn

                                          In general, the higher-up the call stack that you can make a change, the better. Doing it on OnCancel() is as high up as you can go. The reasoning being, the higher-up layers are less likely to change between versions of MFC (thus breaking your code), and higher-up changes are easier for others to maintain. PreTranslateMessage() deals with the raw messages, you may perhaps run into weird cases regarding key states, shift states, and so on. --Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | NEW!! PimpFish | CP SearchBar v3.0 | C++ Forum FAQ

                                          R Offline
                                          R Offline
                                          Rajesh R Subramanian
                                          wrote on last edited by
                                          #37

                                          Michael Dunn wrote:

                                          In general, the higher-up the call stack that you can make a change, the better.

                                          Very good. But if it does not just solve the purpose, then I do not think it it is a sin to move a little lower into the stack! I read this same solution in your FAQ also. But it just is not the way to do it.

                                          Doing this will stop the dialog from closing by clicking the cancel button or the X button even.

                                          However it may prevent the dialog from closing on 'Escape' button press. But to solve a problem, I do not want to run into other problems.

                                          How will i ever close the dialog then?

                                          Add another button for it? Huh?

                                          Michael Dunn wrote:

                                          you may perhaps run into weird cases regarding key states, shift states, and so on.

                                          Nothing weird. Shift state is readily available at GetKeyState(). I strongly believe that you would edit your FAQ also. Think on it! Regards, Rajesh R. Subramanian. You have an apple and me too. We exchange those and We have an apple each. You have an idea and me too. We exchange those and We have two ideas each. -- modified at 2:03 Wednesday 25th January, 2006

                                          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