Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 493
  • Last Modified:

Disabling button using OnUpdate handler

Is it possible to disable (via EnableWindow( FALSE ) or some other documented mechanism) a CButton control in a VC 1.52 CRecordView by using an ON_UPDATE_COMMAND_UI handler ?  I know I could probably do it via a custom DDX routine (examine the value for the field, then disable the control) but for various reasons I don't really want to write another custom DDX routine for this application (although if I have to, I will).  Thanks.
0
xn12z9i
Asked:
xn12z9i
1 Solution
 
richhxbCommented:
Just use UpdateData to get the value for the field,
then enable or disable the control according to the
value using EnableWindow.


0
 
xn12z9iAuthor Commented:
From what function/handler should I call UpdateData() ? I've already tried doing this from my ON_UPDATE_COMMAND_UI handler. Also, as this is a Recordview, I would prefer to let the framework call UpdateData() so that my recordset does not get clobbered.

I guess what I want to know is, will the following work, and if not, what is the best way to implement what I want from a single handler function ?

ON_UPDATE_COMMAND_UI(IDC_MY_BUTTON, OnUpdateMyButton1)

void CMyRecordView::OnUpdateMyButton1(CCmdUI *pCmdUI)
{
    CButton *pb = (CButton *) GetDlgItem( IDC_MY_BUTTON );

    if( pb->GetCheck() )
        pCmdUI->Enable( FALSE );
    else
        pCmdUI->Enable( TRUE );
}
0
 
WBerthinCommented:
THE FOLLOWING WILL WORK TO "GRAY" THE CONTROL
      
CWnd* pButton = GetDlgItem(IDC_MY_BUTTON );
pButton->EnableWindow(FALSE);

And of course substitute TRUE for FALSE to put the
button back on.

If you have the ON_UPDATE_COMMAND_UI handler set up
right you should be OK with this.

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now