#define ILC_COLOR8 0x0008 //256色
#define ILC_COLOR16 0x0010 //16位色
#define ILC_COLOR24 0x0018 //24位色
#define ILC_COLOR32 0x0020 //32位色
制作真彩工具栏的主要步骤:
IDB_TOOLBARCOLOR、IDB_TOOLBARDISABLE、IDB_TOOLBARHOT
CImageList m_imageToolBarDisable;
CImageList m_imageToolBarHot;
void InitToolBar();
| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar.LoadToolBar( IDR_TOOLBAR )) //指定工具栏ID号
{
TRACE0("Failed to create toolbar/n");
return -1; // fail to create
}
InitToolBar(); //设置真彩工具栏
{
CBitmap bm;
m_imageToolBar.Create( 48, 48, TRUE | ILC_COLOR32, 7, 0 );
bm.LoadBitmap( IDB_TOOLBARCOLOR );
m_imageToolBar.Add( &bm,(CBitmap*)NULL );
bm.Detach();
m_wndToolBar.GetToolBarCtrl().SetImageList( &m_imageToolBar );
m_imageToolBarDisable.Create( 48, 48, TRUE | ILC_COLOR32, 7, 0 );
m_imageToolBarDisable.Add( &bm,(CBitmap*)NULL );
bm.Detach();
m_wndToolBar.GetToolBarCtrl().SetDisabledImageList( &m_imageToolBarDisable );
m_imageToolBarHot.Create( 48, 48, TRUE | ILC_COLOR32, 7, 0 );
bm.LoadBitmap( IDB_TOOLBARHOT );
m_imageToolBarHot.Add( &bm,(CBitmap*)NULL );
bm.Detach();
m_wndToolBar.GetToolBarCtrl().SetHotImageList( &m_imageToolBarHot );
}
====================================
CCmdUI does not have a base class.
When a user of your application pulls down a menu, each menu item needs to know whether it should be displayed as enabled or disabled. The target of a menu command provides this information by implementing an ON_UPDATE_COMMAND_UI handler. For each of the command user-interface objects in your application, use the Properties window to create a message-map entry and function prototype for each handler.
When the menu is pulled down, the framework searches for and calls each ON_UPDATE_COMMAND_UI handler, each handler calls CCmdUI member functions such as Enable and Check, and the framework then appropriately displays each menu item.
A menu item can be replaced with a control-bar button or other command user-interface object without changing the code within the ON_UPDATE_COMMAND_UI handler.
The following table summarizes the effect CCmdUI's member functions have on various command user-interface items.
User-Interface Item | Enable | SetCheck | SetRadio | SetText |
---|---|---|---|---|
Menu item | Enables or disables | Checks (×) or unchecks | Checks using dot (•) | Sets item text |
Toolbar button | Enables or disables | Selects, unselects, or indeterminate | Same as SetCheck | (Not applicable) |
Status-bar pane | Makes text visible or invisible | Sets pop-out or normal border | Same as SetCheck | Sets pane text |
Normal button in CDialogBar | Enables or disables | Checks or unchecks check box | Same as SetCheck | Sets button text |
Normal control in CDialogBar | Enables or disables | (Not applicable) | (Not applicable) | Sets window text |
When the user pulls down a menu, the window to which the menu is attached receives a series of messages. Among the first to arrive is a WM_INITMENU message notifying the window that a top-level menu item was selected. Before a submenu is displayed, the window receives a WM_INITMENUPOPUP message. Windows programs sometimes take this opportunity to update the submenu's menu items—for example, putting a check mark next to the Toolbar item in the View menu if the application's toolbar is displayed or unchecking the menu item if the toolbar is currently hidden. As the highlight travels up and down the menu, the window receives WM_MENUSELECT messages reporting the latest position in the menu. In SDK-style programs, WM_MENUSELECT messages are sometimes used to display context-sensitive menu help in a status bar.
The most important message of all is the WM_COMMAND message sent when the user selects an item from the menu. The low word of the message's wParam parameter holds the item's command ID. SDK programmers often use switch-case logic to vector execution to the appropriate handling routine, but MFC provides a better way. An ON_COMMAND statement in the message map links WM_COMMAND messages referencing a particular menu item to the class member function, or command handler, of your choice. The following message-map entry tells MFC to call OnFileSave when the ID_FILE_SAVE menu item is selected