Solved

ON_COMMAND_UPPDATE_UI and CButton

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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
has77  challenge 9 93
fix34  challenge 9 148
sumHeights2  challenge 7 117
ASP.NET C# MessageBox.Show Showing a modal dialog box or form when the application ... 2 168
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

820 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