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. How to hide a button?

How to hide a button?

Scheduled Pinned Locked Moved C / C++ / MFC
questiontutorial
7 Posts 4 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.
  • V Offline
    V Offline
    Vassili
    wrote on last edited by
    #1

    Question: Is it possible to hide and to inactivate a button on a dialogbox if a certain condition has occured?

    D C 2 Replies Last reply
    0
    • V Vassili

      Question: Is it possible to hide and to inactivate a button on a dialogbox if a certain condition has occured?

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

      ShowWindow(SW_HIDE) EnableWindow(FALSE)

      1 Reply Last reply
      0
      • V Vassili

        Question: Is it possible to hide and to inactivate a button on a dialogbox if a certain condition has occured?

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

        get access to the button (or other control) inside the dialog (this is the this in the code !) if its allready exists as a member var, everythings fine ... myBnt.EnableWindow( FALSE ); myBnt.ShowWindow( SW_HIDE ); if not get its CWnd-Pointer via the controls resource id : CWnd* pBnt = this->GetDlgItem( IDC_BUTTON1 ); if(pBnt != NULL) pBnt->EnableWindow( FALSE ); if(pBnt != NULL) pBnt->ShowWindow( SW_HIDE );

        V 1 Reply Last reply
        0
        • C csc

          get access to the button (or other control) inside the dialog (this is the this in the code !) if its allready exists as a member var, everythings fine ... myBnt.EnableWindow( FALSE ); myBnt.ShowWindow( SW_HIDE ); if not get its CWnd-Pointer via the controls resource id : CWnd* pBnt = this->GetDlgItem( IDC_BUTTON1 ); if(pBnt != NULL) pBnt->EnableWindow( FALSE ); if(pBnt != NULL) pBnt->ShowWindow( SW_HIDE );

          V Offline
          V Offline
          Vassili
          wrote on last edited by
          #4

          Thanks a lot! Meanwhile I found that it also seems to work with: myB.ShowWindow(SW_HIDE); and myB.ShowWindow(SW_SHOWNORMAL); Is there a difference between myB.ShowWindow(SW_SHOWNORMAL); and myB.EnableWindow( FALSE ); Another question: In my application I do not have any 'OK' or 'Cancel' buttons. But if I press the enter button on my keybord the application terminates... and I don't know why.

          D R C 3 Replies Last reply
          0
          • V Vassili

            Thanks a lot! Meanwhile I found that it also seems to work with: myB.ShowWindow(SW_HIDE); and myB.ShowWindow(SW_SHOWNORMAL); Is there a difference between myB.ShowWindow(SW_SHOWNORMAL); and myB.EnableWindow( FALSE ); Another question: In my application I do not have any 'OK' or 'Cancel' buttons. But if I press the enter button on my keybord the application terminates... and I don't know why.

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

            Vassili wrote: Is there a difference between myB.ShowWindow(SW_SHOWNORMAL); and myB.EnableWindow( FALSE ); Yes. Vassili wrote: In my application I do not have any 'OK' or 'Cancel' buttons. But if I press the enter button on my keybord the application terminates... and I don't know why. Even though you don't have an OnOK() or OnCancel() handler, the defaults are still being called. They, in turn, call EndDialog().

            1 Reply Last reply
            0
            • V Vassili

              Thanks a lot! Meanwhile I found that it also seems to work with: myB.ShowWindow(SW_HIDE); and myB.ShowWindow(SW_SHOWNORMAL); Is there a difference between myB.ShowWindow(SW_SHOWNORMAL); and myB.EnableWindow( FALSE ); Another question: In my application I do not have any 'OK' or 'Cancel' buttons. But if I press the enter button on my keybord the application terminates... and I don't know why.

              R Offline
              R Offline
              Rage
              wrote on last edited by
              #6

              Vassili wrote: Is there a difference between myB.ShowWindow(SW_SHOWNORMAL); and myB.EnableWindow( FALSE ); Yes. ShowWindow will only hide the button, but it will still be there and active, the only thing is you can'T see it. If for some reason, it gets displayed again (Some lost message ..) the user can use it. EnableWindow really disables the button functionnality. If you use these functions on a "usual" button (CButton), ShowWindow(SW_HIDE) will make it disappear whereas EnableWindow(False) will make it unclickable and will grey its caption. I think this make clearer the difference between hiding a control and disabling it. Vassili wrote: n my application I do not have any 'OK' or 'Cancel' buttons. But if I press the enter button on my keybord the application terminates... and I don't know why. From Mike Dunn's FAQ : http://www.codeproject.com/cpp/cppforumfaq.asp#mfc_dlgclosekeys[^] ~RaGE();

              1 Reply Last reply
              0
              • V Vassili

                Thanks a lot! Meanwhile I found that it also seems to work with: myB.ShowWindow(SW_HIDE); and myB.ShowWindow(SW_SHOWNORMAL); Is there a difference between myB.ShowWindow(SW_SHOWNORMAL); and myB.EnableWindow( FALSE ); Another question: In my application I do not have any 'OK' or 'Cancel' buttons. But if I press the enter button on my keybord the application terminates... and I don't know why.

                C Offline
                C Offline
                csc
                wrote on last edited by
                #7

                the other question ... the ok and cancel button which are not there but working via keystrokes ... If you want to do nothing in your dialog, just override the default handlers of these keys : class CMyDialog::CDialog { . . virtual void OnOK( ) { /* do nothing*/ }; virtual void OnCancel( ) { /* do nothing*/ }; } for details look at the msdn descriptions of these cdialog members, for example OnOk : CDialog::OnOK virtual void OnOK( ); Remarks Called when the user clicks the OK button (the button with an ID of IDOK). Override this member function to perform the OK button action. If the dialog box includes automatic data validation and exchange, the default implementation of this member function validates the dialog-box data and updates the appropriate variables in your application. If you implement the OK button in a modeless dialog box, you must override the OnOK member function and call DestroyWindow from within it. Don’t call the base-class member function, because it calls EndDialog, which makes the dialog box invisible but does not destroy it.

                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