Solved

Enabling & Disabling Toolbar items at runtime in MFC SDI...

Posted on 2003-12-10
5
949 Views
Last Modified: 2013-11-20
Hi,

I have an SDI application containing a Menu (IDR_MENU) and a Toolbar (IDR_TOOLBAR1).

When a perform click a certain button or menu item (RUN), I want specific menu items and Toolbar icons to become disabled.  Each associated Toolbar Icon and Menu Item have the same ID (ID_ABORT for example).

I use the following to disable the 'Abort' functionality when it is NOT running...

void CMainFrame::OnUpdateFileAbort(CCmdUI* pCmdUI)
{
   if (isRunning == false) pCmdUI->Enable(FALSE);
}

This works fine for the Menu item, but does not change the Toolbar icon.

Any ideas where I am going wrong...

James
0
Comment
Question by:jatkin
  • 2
  • 2
5 Comments
 
LVL 48

Expert Comment

by:AlexFM
Comment Utility
void CMainFrame::OnUpdateFileAbort(CCmdUI* pCmdUI)
{
  pCmdUI->Enable(! running);
}

This should work in standard SDI application created by MGC Application Wizard. Just set running flag when necessary.
0
 
LVL 23

Expert Comment

by:Roshan Davis
Comment Utility
Please make sure that the toolbar is also using the same id.
0
 
LVL 4

Author Comment

by:jatkin
Comment Utility
I get the same response - Menu works as expected, Toolbar does not change.  IDs are the same in the Menu & Toolbar...

As the function that sets the variable to enable & disable the toolbar & menu items is sequencial, do I need to FORCE some sort of update to occur DURING its execution ?

i.e.
void CMyView::DoIt()
{
   Running = true;
   <Force the toolbar to update>
   ... Do some stuff ...
   <Force the toolbar to update>
   Running = false;
}
0
 
LVL 48

Accepted Solution

by:
AlexFM earned 100 total points
Comment Utility
OK, now it is clear. <Force the toolbar to update> is:

CWinApp::OnIdle(0);
0
 
LVL 4

Author Comment

by:jatkin
Comment Utility
As usual, you are an absolute genius!!!!

Thanks for your help...

James
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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: 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. …
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.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

771 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

9 Experts available now in Live!

Get 1:1 Help Now