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. Disable Close Button in the Dialog's Caption

Disable Close Button in the Dialog's Caption

Scheduled Pinned Locked Moved C / C++ / MFC
question
12 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.
  • E Eugene Pustovoyt

    How disable the close button in the caption of the Dialog? Thanks:confused:

    S Offline
    S Offline
    solex
    wrote on last edited by
    #2

    What do you mean by "in the caption" Would GetDlgItem(ID_CLOSE)->EnableWindow(FALSE); do? A vast majority of our imports comes from outside the country. George W. Bush

    E 1 Reply Last reply
    0
    • E Eugene Pustovoyt

      How disable the close button in the caption of the Dialog? Thanks:confused:

      T Offline
      T Offline
      Tomasz Sowinski
      wrote on last edited by
      #3

      I don't think it's possible unless you draw the caption and its buttons yourself in WM_NCPAINT. Why do you need this functionality? Tomasz Sowinski -- http://www.shooltz.com

      E 1 Reply Last reply
      0
      • T Tomasz Sowinski

        I don't think it's possible unless you draw the caption and its buttons yourself in WM_NCPAINT. Why do you need this functionality? Tomasz Sowinski -- http://www.shooltz.com

        E Offline
        E Offline
        Eugene Pustovoyt
        wrote on last edited by
        #4

        In some cases it is necessary for me to forbid for the user to make a cancellation, and button Close is equivalent to a cancellation!

        1 Reply Last reply
        0
        • E Eugene Pustovoyt

          How disable the close button in the caption of the Dialog? Thanks:confused:

          D Offline
          D Offline
          Deepak Khajuria
          wrote on last edited by
          #5

          Disabling the menu items in system menu disables the buttons on the Caption Bar. The following code should do:

          CMenu \*pMenu= GetSystemMenu(FALSE);
          pMenu->EnableMenuItem(SC\_CLOSE,MF\_BYCOMMAND|MF\_DISABLED);
          pMenu->RemoveMenu(SC\_CLOSE,MF\_BYCOMMAND);
          

          Deepak Khajuria

          T O 2 Replies Last reply
          0
          • D Deepak Khajuria

            Disabling the menu items in system menu disables the buttons on the Caption Bar. The following code should do:

            CMenu \*pMenu= GetSystemMenu(FALSE);
            pMenu->EnableMenuItem(SC\_CLOSE,MF\_BYCOMMAND|MF\_DISABLED);
            pMenu->RemoveMenu(SC\_CLOSE,MF\_BYCOMMAND);
            

            Deepak Khajuria

            T Offline
            T Offline
            Tomasz Sowinski
            wrote on last edited by
            #6

            Nice trick! :-D I've checked this on W2K - it's enough to call EnableMenuItem. Also, if for some reason it's OK to leave disabled item in the system menu, then MF_GRAYED instead of MF_DISABLED will be better - the menu item will actually look disabled. Tomasz Sowinski -- http://www.shooltz.com

            E 1 Reply Last reply
            0
            • S solex

              What do you mean by "in the caption" Would GetDlgItem(ID_CLOSE)->EnableWindow(FALSE); do? A vast majority of our imports comes from outside the country. George W. Bush

              E Offline
              E Offline
              Eugene Pustovoyt
              wrote on last edited by
              #7

              What's the ID_CLOSE

              1 Reply Last reply
              0
              • T Tomasz Sowinski

                Nice trick! :-D I've checked this on W2K - it's enough to call EnableMenuItem. Also, if for some reason it's OK to leave disabled item in the system menu, then MF_GRAYED instead of MF_DISABLED will be better - the menu item will actually look disabled. Tomasz Sowinski -- http://www.shooltz.com

                E Offline
                E Offline
                Eugene Pustovoyt
                wrote on last edited by
                #8

                Great, it's work! Thanks everybody for help!!!! Best regards, Eugene Pustovoyt :-D

                A 1 Reply Last reply
                0
                • E Eugene Pustovoyt

                  Great, it's work! Thanks everybody for help!!!! Best regards, Eugene Pustovoyt :-D

                  A Offline
                  A Offline
                  Alvaro Mendez
                  wrote on last edited by
                  #9

                  I'm glad you got it working, but you may consider that instead of disabling the Close button, you let the user press it but then show him a message box explaining why it's wrong to do so. Sometimes this is a more user-friendly way to go, since it doesn't leave the user wondering why he can't do something he's normally allowed to do (like closing windows), and then perhaps picking up the phone to ask Tech Support. If you tell him with a message box, he'll know right away. Regards, Alvaro

                  E 1 Reply Last reply
                  0
                  • A Alvaro Mendez

                    I'm glad you got it working, but you may consider that instead of disabling the Close button, you let the user press it but then show him a message box explaining why it's wrong to do so. Sometimes this is a more user-friendly way to go, since it doesn't leave the user wondering why he can't do something he's normally allowed to do (like closing windows), and then perhaps picking up the phone to ask Tech Support. If you tell him with a message box, he'll know right away. Regards, Alvaro

                    E Offline
                    E Offline
                    Eugene Pustovoyt
                    wrote on last edited by
                    #10

                    Very good remark, but I do not know as it is possible to handle the message from the button taking place outside of client parts of dialog! Therefore I while shall leave as am! If you may prompt me how make that about what you wrote (it is desirable with an example of a code) I shall be very grateful to you. :omg:

                    A 1 Reply Last reply
                    0
                    • E Eugene Pustovoyt

                      Very good remark, but I do not know as it is possible to handle the message from the button taking place outside of client parts of dialog! Therefore I while shall leave as am! If you may prompt me how make that about what you wrote (it is desirable with an example of a code) I shall be very grateful to you. :omg:

                      A Offline
                      A Offline
                      Alvaro Mendez
                      wrote on last edited by
                      #11

                      When the user presses the Close button, the WM_CLOSE message is sent to the dialog box. Use the Class Wizard to add a handler (OnClose) for that message and you can write your code in there. Regards, Alvaro

                      1 Reply Last reply
                      0
                      • D Deepak Khajuria

                        Disabling the menu items in system menu disables the buttons on the Caption Bar. The following code should do:

                        CMenu \*pMenu= GetSystemMenu(FALSE);
                        pMenu->EnableMenuItem(SC\_CLOSE,MF\_BYCOMMAND|MF\_DISABLED);
                        pMenu->RemoveMenu(SC\_CLOSE,MF\_BYCOMMAND);
                        

                        Deepak Khajuria

                        O Offline
                        O Offline
                        Orgen Kl
                        wrote on last edited by
                        #12

                        Very good, this works fine. This disables the main windows close button. How can I disable the close button form a child window, say a open document in a mdi application? Thanks for you help juergen

                        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