Solved

ON_COMMAND_UPPDATE_UI and CButton

Posted on 2002-07-29
7
580 Views
Last Modified: 2013-11-20
How do I make a CButton in a CView sencible to Enable/Disable state due to change of pCmdUI->Enable()?
0
Comment
Question by:morefalt
  • 2
  • 2
7 Comments
 
LVL 23

Expert Comment

by:Roshan Davis
Comment Utility
How do I make a CButton in a CView sencible to Enable/Disable state due to change of pCmdUI->Enable()?


Made the CButton member to public, or add a public function to get the CButton pointer,

If SDI use GetAciveView()
cast it into your view

and use EnableWindow API or function.


Good Luck
0
 
LVL 30

Accepted Solution

by:
Zoppo earned 500 total points
Comment Utility
Hi morefalt,

add a message handler for WM_IDLEUPDATECMDUI to your
view like this:

// you need to include afxpriv.h
#include "afxpriv.h"

// ID_TEST_BUTTON is the resource ID I used for the button
BEGIN_MESSAGE_MAP(CMyView, CView)
 //{{AFX_MSG_MAP(CMyView)
 ...
 //}}AFX_MSG_MAP
 ON_UPDATE_COMMAND_UI(ID_TEST_BUTTON, OnUpdateTestButton)
 ON_MESSAGE( WM_IDLEUPDATECMDUI, OnIdleUpdateUIMessage )
END_MESSAGE_MAP()


//add prototypes in .h file, i.e.

...
//{{AFX_MSG(CMyView)
...
//}}AFX_MSG
afx_msg void OnUpdateTestButton(CCmdUI* pCmdUI);
afx_msg LRESULT OnIdleUpdateUIMessage(WPARAM, LPARAM);
DECLARE_MESSAGE_MAP()
...


// add the functions in .cpp file, i.e.
void CMyView::OnUpdateTestButton( CCmdUI* pCmdUI )
{
 pCmdUI->Enable( ... );
}

LRESULT CMyView::OnIdleUpdateUIMessage(WPARAM, LPARAM)
{
 UpdateDialogControls( this, TRUE );
 return 0;
}



hope that helps,

ZOPPO
0
 
LVL 23

Expert Comment

by:Roshan Davis
Comment Utility
How do I make a CButton in a CView sencible to Enable/Disable state due to change of pCmdUI->Enable()?


Made the CButton member to public, or add a public function to get the CButton pointer,

If SDI use GetAciveView()
cast it into your view

and use EnableWindow API or function.


Good Luck
0
 
LVL 2

Expert Comment

by:SamratAshok
Comment Utility
I am not too sure, but adding message map
ON_UPDATE_COMMAND_UI(ID_TEST_BUTTON, OnUpdateTestButton)
should cause application to loop forever.

ON_UPDATE_COMMAND_UI can only be used for menus and like.
0
 
LVL 30

Expert Comment

by:Zoppo
Comment Utility
Hmm ... I don't know why you think this ... anyway, I
tested the code before I posted it here and it works
perfectly well.

ON_UPDATE_COMMAND_UI macro only adds an entry to the
window's message map for CN_UPDATE_COMMAND_UI message
and maps it to a function.
UpdateDialogControls creates a CCmdUI and passes it
with a CN_UPDATE_COMMAND_UI message to all descendant
windows.
The calls to CCmdUI::SetCheck() or CCmdUI::Enable()
directly send BM_SETCHECK message to buttons or calls
CWnd::EnableWindow() for the control.

There's no problem to do this in other windows than
toolbars or menus.

Further, i.e. MSDN Technical Note TN021 states that
one can use exactly this technique to handle control's
states of a dialog through the parent window of the
dialog.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
centeredAverage challenge 8 119
post4 challenge 28 81
Detect file exist or not 3 74
Change to event 1 71
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: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

728 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

10 Experts available now in Live!

Get 1:1 Help Now