Solved

ON_UPDATE_COMMAND_UI vs ON_COMMAND

Posted on 2010-11-12
3
1,193 Views
Last Modified: 2012-05-10
Previously in MFC I've managed to use the ON_UPDATE_COMMAND_UI handler to set the state of check boxes and buttons on application menu bars and let ON_COMMAND set the new state.

I'm now using a ribbon bar with a CBCGPRibbonSlider on it. The position of the slider maintained by ON_UPDATE.. and a change to the position from the ON_COMMAND handler.

THE PROBLEM is in the ON_COMMAND handler I use pCtrl->GetPos(); only to find that the ON_UPDATE_COMMAND_UI has already set it back to the previous position.

I could ignore the GetPos value but have no other CBCGPRibbonSlider method to know its new position.

Am I going about the UPDATE + COMMAND interface the wrong way or should the CBCGPRibbonSlider return the position better?

void CMainFrame::OnMapDDIDetails()

{

	int iDDIViewDetails = -1;

	CBCGPRibbonSlider* pCtrl  = (CBCGPRibbonSlider*)m_wndRibbonBar.FindByID(IDC_MAP_DDI_DETAILS, FALSE);

	if(pCtrl!=NULL)

	{

		iDDIViewDetails = pCtrl->GetPos();

		if((iDDIViewDetails>=0)||(iDDIViewDetails<=2))

			ChangeDetails(iDDIViewDetails);

	}

}

void CMainFrame::OnUpdateMapDDIDetails(CCmdUI* pCmdUI)

{

	int iDDIViewDetails = -1;

	CBCGPRibbonSlider* pCtrl  = (CBCGPRibbonSlider*)m_wndRibbonBar.FindByID(IDC_MAP_DDI_DETAILS, FALSE);

	if(pCtrl!=NULL)

	{

		iDDIViewDetails = GetDetailState();

		if((iDDIViewDetails>=0)||(iDDIViewDetails<=2))

			pCtrl->SetPos(iDDIViewDetails);

	}

}

Open in new window

0
Comment
Question by:itdeptneci
3 Comments
 
LVL 31

Accepted Solution

by:
Zoppo earned 500 total points
ID: 34119674
Hi itdeptneci,

the only way to avoid this is to simply not set the control's position within the ON_UPDATE_COMMAND_UI handler. The ON_UPDATE_COMMAND_UI handler is used to implement the visible state of a GUI element's, it's not intended to be used to update data which might be associated with that control. And IMO this is really senseful, since if one uses a ON_COMMAND_UPDATE_UI handler to change any data may initiate another ON_UPDATE_COMMAND_UI.

So, I would suggest you add a 'int' member to your applications document - in 'OnMapDDIDetails' you can retrieve its value as you now do for 'iDDIViewDetails'. In 'OnUpdateMapDDIDetails' just handle visibility/disabled-state of the control. Add a 'OnActivateView' handler and use the 'SetPos' there as you before did in 'OnUpdateMapDDIDetails'.

Hope that helps,

ZOPPO
0
 
LVL 40

Expert Comment

by:evilrix
ID: 34824134
This question has been classified as abandoned and is being closed as part of the Cleanup Program. See my comment at the end of the question for more details.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

895 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

13 Experts available now in Live!

Get 1:1 Help Now