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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. SIMPLE: "x" in System menu

SIMPLE: "x" in System menu

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

    What is the event message when the user clicks the x in the system menu. Background: I have disabled OnCancel() and OnOK() so that in my dialog-based app the esc and return keys don't close the app. I have the OnFileExit (when user selects file exit) method calling EndDialog(IDOK) directly. What function is called when the user clicks on the x? Long and short of it is I dont want keyboard commands (other than alt navigation) to close the app.

    D S 2 Replies Last reply
    0
    • J JKallen

      What is the event message when the user clicks the x in the system menu. Background: I have disabled OnCancel() and OnOK() so that in my dialog-based app the esc and return keys don't close the app. I have the OnFileExit (when user selects file exit) method calling EndDialog(IDOK) directly. What function is called when the user clicks on the x? Long and short of it is I dont want keyboard commands (other than alt navigation) to close the app.

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      JKallen wrote: What function is called when the user clicks on the x? Have you looked at OnClose()?


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

      J 1 Reply Last reply
      0
      • J JKallen

        What is the event message when the user clicks the x in the system menu. Background: I have disabled OnCancel() and OnOK() so that in my dialog-based app the esc and return keys don't close the app. I have the OnFileExit (when user selects file exit) method calling EndDialog(IDOK) directly. What function is called when the user clicks on the x? Long and short of it is I dont want keyboard commands (other than alt navigation) to close the app.

        S Offline
        S Offline
        Shog9 0
        wrote on last edited by
        #3

        The message WM_SYSCOMMAND, with the command id SC_CLOSE

        rather than leaving it visible and making it non-functional. This sort of thing is confusing and frustrating to users.
        To hide: remove the WS_SYSMENU style from the window. To disable: retrieve the system menu by calling GetSystemMenu(), then disable and gray the SC_CLOSE option by calling EnableMenuItem(). You should then disable the command (and also the Alt+F4 mnemonic)by intercepting the WM_SYSCOMMAND message and avoiding the default behavior if the command ID is SC_CLOSE.

        Shog9

        I'm not the Jack of Diamonds... I'm not the six of spades. I don't know what you thought; I'm not your astronaut...

        J 1 Reply Last reply
        0
        • D David Crow

          JKallen wrote: What function is called when the user clicks on the x? Have you looked at OnClose()?


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

          J Offline
          J Offline
          JKallen
          wrote on last edited by
          #4

          Yes. The problem is esc and return call OnOK and OnCancel, so doing anything to OnClose wont change anything. I think the problem is that clicking the x calls OnCancel (or OnOK doesnt matter which for my purposes). I need a way to differentiate between hitting the return key and the esc key from clicking the x or selecting file close. I dont want to get into Virtual Keys right now. Im not at that stage in writing this application yet. I try to write applications in phases. It makes things much simpler when I add functionality in groups.

          D 1 Reply Last reply
          0
          • S Shog9 0

            The message WM_SYSCOMMAND, with the command id SC_CLOSE

            rather than leaving it visible and making it non-functional. This sort of thing is confusing and frustrating to users.
            To hide: remove the WS_SYSMENU style from the window. To disable: retrieve the system menu by calling GetSystemMenu(), then disable and gray the SC_CLOSE option by calling EnableMenuItem(). You should then disable the command (and also the Alt+F4 mnemonic)by intercepting the WM_SYSCOMMAND message and avoiding the default behavior if the command ID is SC_CLOSE.

            Shog9

            I'm not the Jack of Diamonds... I'm not the six of spades. I don't know what you thought; I'm not your astronaut...

            J Offline
            J Offline
            JKallen
            wrote on last edited by
            #5

            OK That worked. I aggree with respect to irritating users. What I have done (which works) in case you are interested is 1) disabled the OnOK and OnCancel to address the user hitting the esc and return keys 2) created an event handler to deal with user clicking file exit that calls EndDialog(IDOK) 3) edited the OnSysCommand function so that if SC_CLOSE is the message, it calls EndDialog(IDOK) as well Exactly the result I was looking for. Thanks.

            1 Reply Last reply
            0
            • J JKallen

              Yes. The problem is esc and return call OnOK and OnCancel, so doing anything to OnClose wont change anything. I think the problem is that clicking the x calls OnCancel (or OnOK doesnt matter which for my purposes). I need a way to differentiate between hitting the return key and the esc key from clicking the x or selecting file close. I dont want to get into Virtual Keys right now. Im not at that stage in writing this application yet. I try to write applications in phases. It makes things much simpler when I add functionality in groups.

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #6

              JKallen wrote: I need a way to differentiate between hitting the return key and the esc key from clicking the x or selecting file close. Then implement the following handlers:

              OnOK()
              OnCancel()
              OnClose()
              DestroyWindow()

              and note when each are called (e.g., breakpoint, message box).


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

              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