Solved

Disabling button using OnUpdate handler

Posted on 1998-01-06
3
466 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
mixString challenge 36 120
unable to delete all specified values regedit 38 383
tripleUp challenge 7 78
Line meaning 9 85
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

816 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

8 Experts available now in Live!

Get 1:1 Help Now