Solved

Disabling button using OnUpdate handler

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
bobThere java chalenge 45 84
not able to insert into temp table 68 150
canBalance challenge 34 65
Change to event 1 73
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

757 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

16 Experts available now in Live!

Get 1:1 Help Now