Step 1:
Declare the member variables in the mainframe. h file:
CToolBar m_hotToolBar;
Create a toolbar in cmainframe: oncreate (). Assume that you have created a toolbar resource and two bitmap resources: idb_toolbar_cold and idb_toolbar_hot. The former indicates normal buttons, the latter indicates the status button when the mouse moves above. Use the following code to create a toolbar:
if (!m_hotToolBar.CreateEx(this, TBSTYLE_FLAT | TBSTYLE_LIST, WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) || !m_hotToolBar.LoadToolBar(IDR_HOTBAR)) { TRACE0("Failed to create toolbar/n"); return -1; // fail to create }
Step 2:
Add the following code in cmainframe: oncreate () to access bitmap resources:
// Set up hot bar image lists. CImageList imageList; CBitmap bitmap; // Create and set the normal toolbar image list. bitmap.LoadBitmap(IDB_TOOLBAR_COLD); imageList.Create(21, 20, ILC_COLORDDB|ILC_MASK, 13, 1); imageList.Add(&bitmap, RGB(255,0,255)); m_hotToolBar.SendMessage(TB_SETIMAGELIST, 0, (LPARAM)imageList.m_hImageList); imageList.Detach(); bitmap.Detach(); // Create and set the hot toolbar image list. bitmap.LoadBitmap(IDB_TOOLBAR_HOT); imageList.Create(21, 20, ILC_COLORDDB|ILC_MASK, 13, 1); imageList.Add(&bitmap, RGB(255,0,255)); m_hotToolBar.SendMessage(TB_SETHOTIMAGELIST, 0, (LPARAM)imageList.m_hImageList); imageList.Detach(); bitmap.Detach();