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

x
?
Solved

ON_COMMAND_UPPDATE_UI and CButton

Posted on 2002-07-29
7
Medium Priority
?
603 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
ID: 7184892
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 31

Accepted Solution

by:
Zoppo earned 2000 total points
ID: 7184894
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
ID: 7184915
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
ID: 7189437
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 31

Expert Comment

by:Zoppo
ID: 7189864
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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

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 …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

916 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