Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 976
  • Last Modified:

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

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
James Atkin
Asked:
James Atkin
  • 2
  • 2
1 Solution
 
AlexFMCommented:
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
 
Roshan DavisCommented:
Please make sure that the toolbar is also using the same id.
0
 
James AtkinSenior Principle Software EngineerAuthor Commented:
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
 
AlexFMCommented:
OK, now it is clear. <Force the toolbar to update> is:

CWinApp::OnIdle(0);
0
 
James AtkinSenior Principle Software EngineerAuthor Commented:
As usual, you are an absolute genius!!!!

Thanks for your help...

James
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now