Solved

ON_COMMAND_UPPDATE_UI and CButton

Posted on 2002-07-29
7
597 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

623 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