Solved

ON_COMMAND_UPPDATE_UI and CButton

Posted on 2002-07-29
7
590 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 500 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Generic progress indicator 6 117
Expand data scrubbing tool 13 32
Shell script to login to remote m/c and execute commands 10 78
"Black Box" Testing of Control System Software 2 53
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

832 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