• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 464
  • Last Modified:

mfc mdi .net toolbar

I have the standard mfc toolbar created when you make a new mdi project. I added three new buttons using the resource editor. When i run the pgrogram they apper disabled. I tried to enable them with:

m_wndToolBar.SetButtonStyle(9, m_wndToolBar.GetButtonStyle(9) & ~TBBS_DISABLED);

and it works for a split second then reverts to being disabled.

  • 2
1 Solution
Toolbar button are automatically disabled if there is no commanf handler for them. Add handlers and they will be enanled.
To enable/disable toolbar buttons use ON_UPDATE_UI handlers.
as2003Author Commented:
Yeah, I found that in the documentation, but I don't know how to use/create/manipulate/find/etc ON_UPDATE_UI handlers
Select class where you want to handle toolbar messages in the Class View . For example, this can be CMainFrame class. In the Properties window click Events tag. Find button ID in the list and expand it. Select  ON_UPDATE_UI item and select handler name from combobox. Fill handler:

void CMainFrame::OnUpdateMyCommand(CCmdUI *pCmdUI)
    pCmdUI->Enable(TRUE);   // instead of TRUE you can use some class member

See details in the CCmdUI class description.

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

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