Solved

Disabling button using OnUpdate handler

Posted on 1998-01-06
3
463 Views
Last Modified: 2013-11-20
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
Comment
Question by:xn12z9i
3 Comments
 
LVL 1

Expert Comment

by:richhxb
ID: 1313497
Just use UpdateData to get the value for the field,
then enable or disable the control according to the
value using EnableWindow.


0
 

Author Comment

by:xn12z9i
ID: 1313498
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
 
LVL 1

Accepted Solution

by:
WBerthin earned 100 total points
ID: 1313499
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to calculate times for developing software? 8 65
string initialization in java 11 109
maven archtype selection in eclipse 1 53
zeroFront challenge 7 79
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

943 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now