Reputation: 119
I'm having trouble understanding just how the View Menu turns off the Standard Toolbar in terms of code.
If I understand correctly, the standard toolbar is defined in the .rc file as follows:
IDR_MAINFRAME TOOLBAR 16, 15
BEGIN
BUTTON ID_FILE_NEW
BUTTON ID_FILE_OPEN
BUTTON ID_FILE_SAVE
SEPARATOR
BUTTON ID_EDIT_CUT
BUTTON ID_EDIT_COPY
BUTTON ID_EDIT_PASTE
SEPARATOR
BUTTON ID_FILE_PRINT
BUTTON ID_APP_ABOUT
END
Similarly the View Menu, which allows you to turn the Standard Toolbar on and off is defined as follows:
IDR_MAINFRAME MENU
BEGIN
POPUP "&File"
BEGIN
MENUITEM "&New\tCtrl+N", ID_FILE_NEW
MENUITEM "&Open...\tCtrl+O", ID_FILE_OPEN
MENUITEM "&Close", ID_FILE_CLOSE
MENUITEM SEPARATOR
MENUITEM "P&rint Setup...", ID_FILE_PRINT_SETUP
MENUITEM SEPARATOR
MENUITEM "Recent File", ID_FILE_MRU_FILE1,GRAYED
MENUITEM SEPARATOR
MENUITEM "E&xit", ID_APP_EXIT
END
POPUP "&View"
BEGIN
POPUP "&Toolbars and Docking Windows"
BEGIN
MENUITEM "<placeholder>", ID_VIEW_TOOLBAR
END
MENUITEM "&Status Bar", ID_VIEW_STATUS_BAR
POPUP "&Application Look"
BEGIN
MENUITEM "Windows &2000", ID_VIEW_APPLOOK_WIN_2000
MENUITEM "Office &XP", ID_VIEW_APPLOOK_OFF_XP
MENUITEM "&Windows XP", ID_VIEW_APPLOOK_WIN_XP
MENUITEM "Office 200&3", ID_VIEW_APPLOOK_OFF_2003
MENUITEM "Visual Studio 200&5", ID_VIEW_APPLOOK_VS_2005
MENUITEM "Visual Studio 200&8", ID_VIEW_APPLOOK_VS_2008
POPUP "Office 200&7"
BEGIN
MENUITEM "&Blue Style", ID_VIEW_APPLOOK_OFF_2007_BLUE
MENUITEM "B&lack Style", ID_VIEW_APPLOOK_OFF_2007_BLACK
MENUITEM "&Silver Style", ID_VIEW_APPLOOK_OFF_2007_SILVER
MENUITEM "&Aqua Style", ID_VIEW_APPLOOK_OFF_2007_AQUA
END
END
END
POPUP "&Help"
BEGIN
MENUITEM "&About Emergence...", ID_APP_ABOUT
END
END
Now my reasoning is this....in order for the MENUITEM that allows you to toggle the Standard Toolbar on and off to work, ID_VIEW_TOOLBAR must somehow reference the toolbar definition itself. I have searched the entire project and nowhere can I find where ID_VIEW_TOOLBAR is associated with the Standard Toolbar definition. Surely there must be some relationship linking ID_VIEW_TOOLBAR to the definition of IDR_MAINFRAME TOOLBAR 16, 15 in order to toggle it on and off??
If not, could you kindly explain how ID_VIEW_TOOLBAR turns off the Standard Toolbar?
Thanks for your time.
Upvotes: 2
Views: 3118
Reputation: 51503
ID_VIEW_TOOLBAR
is a Standard Command ID. TN022: Standard Commands Implementation
explains how these are handled. In case of the ID_VIEW_TOOLBAR
:
ID_VIEW_TOOLBAR
Toggles the toolbar on and offCFrameWnd handles this command and the update-command UI handler to toggle the visible state of the toolbar. The toolbar must be a child window of the frame with child window ID of
AFX_IDW_TOOLBAR
. The command handler actually toggles the visibility of the toolbar window.CFrameWnd::RecalcLayout
is used to redraw the frame window with the toolbar in its new state. The update-command UI handler checks the menu item when the toolbar is visible.Customization of this command handler is not recommended. If you wish to add additional toolbars, you will want to clone and modify the command handler and the update-command UI handler for this command.
The connection is etablished in your CMainFrame::OnCreate
override. It calls m_wndToolBar.CreateEx
, leaving out the final optional parameter: The control ID AFX_IDW_TOOLBAR
. It then proceeds to call m_wndToolBar.LoadToolBar(IDR_MAINFRAME)
. This constructs the toolbar from your TOOLBAR
resource with ID IDR_MAINFRAME
.
Upvotes: 3