How to hide a button?
-
Question: Is it possible to hide and to inactivate a button on a dialogbox if a certain condition has occured?
ShowWindow(SW_HIDE) EnableWindow(FALSE)
-
Question: Is it possible to hide and to inactivate a button on a dialogbox if a certain condition has occured?
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 );
-
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 );
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.
-
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.
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().
-
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.
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();
-
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.
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.