BOOL CMainFrame::CreateExToolBar() { CImageList img; CString str; if(!m_wndReBar.Create(this)) { return -1; } if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC)) { return -1; } m_wndToolBar.GetToolBarCtrl().SetButtonWidth(45, 65); img.Create(35, 35, ILC_COLOR8|ILC_MASK,2,2); img.SetBkColor(::GetSysColor(COLOR_BTNFACE)); img.Add(AfxGetApp()->LoadIcon(IDI_ICON_ADD)); img.Add(AfxGetApp()->LoadIcon(IDI_ICON_DELETE)); img.Add(AfxGetApp()->LoadIcon(IDI_ICON_SERACH)); img.Add(AfxGetApp()->LoadIcon(IDI_ICON_PRINT)); m_wndToolBar.GetToolBarCtrl().SetHotImageList(&img); img.Detach(); img.Create(32, 32, ILC_COLOR8|ILC_MASK, 2,2); img.SetBkColor(::GetSysColor(COLOR_BTNFACE)); img.Add(AfxGetApp()->LoadIcon(IDI_ICON_ADD)); img.Add(AfxGetApp()->LoadIcon(IDI_ICON_DELETE)); img.Add(AfxGetApp()->LoadIcon(IDI_ICON_SERACH)); img.Add(AfxGetApp()->LoadIcon(IDI_ICON_PRINT)); m_wndToolBar.GetToolBarCtrl().SetImageList(&img); img.Detach(); //改变属性 m_wndToolBar.ModifyStyle(0, TBSTYLE_FLAT |CBRS_TOOLTIPS | TBSTYLE_TRANSPARENT|TBBS_CHECKBOX ); m_wndToolBar.SetButtons(NULL,5); // set up each toolbar button设置文字 m_wndToolBar.SetButtonInfo(0, IDM_ADD, TBSTYLE_BUTTON, 0); m_wndToolBar.SetButtonText(0, "添加"); m_wndToolBar.SetButtonInfo(1, IDM_DEL, TBSTYLE_BUTTON, 1); m_wndToolBar.SetButtonText(1, "删除"); m_wndToolBar.SetButtonInfo(2, IDM_SEARCH, TBSTYLE_BUTTON, 2); m_wndToolBar.SetButtonText(2, "查找"); m_wndToolBar.SetButtonInfo(3, IDM_PRINT, TBSTYLE_BUTTON, 3); m_wndToolBar.SetButtonText(3, "打印"); m_wndToolBar.SetButtonInfo(4, IDC_MSG_BUTTONSPLI, TBBS_SEPARATOR, 0); CRect rectToolBar; m_wndToolBar.GetItemRect(0, &rectToolBar); m_wndToolBar.SetSizes(rectToolBar.Size(), CSize(33,33)); m_wndReBar.AddBar(&m_wndToolBar); REBARBANDINFO rbbi; rbbi.cbSize = sizeof(rbbi); rbbi.fMask = RBBIM_CHILDSIZE | RBBIM_IDEALSIZE | RBBIM_SIZE|RBBIM_BACKGROUND; rbbi.cxMinChild = rectToolBar.Width(); rbbi.cyMinChild = rectToolBar.Height(); rbbi.hbmBack = LoadBitmap(::AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_TOOLBARBKMAP)); rbbi.cx = rbbi.cxIdeal = rectToolBar.Width() * 10; m_wndReBar.GetReBarCtrl().SetBandInfo(0, &rbbi); return TRUE; }
补充::
AfxGetApp
The pointer returned by this function can be used to access application information such as the main message-dispatch code or the topmost window.
CWinApp* AfxGetApp( );
返回值:指向应用程序的单一CWinApp对象的指针。
说明:
这个函数返回的指针可以被用来访问应用程序的信息,如主消息调度代码以及顶层窗口等。
CWnd::GetDlgItem
This method retrieves a pointer to the specified control or child window in a dialog box or other window. The pointer returned is usually cast to the type of control identified by nID.
CWnd* GetDlgItem ( int nID ) const; void CWnd::GetDlgItem( int nID, HWND* phWnd ) const;
CButton::SetCheck
This method sets or resets the check state of a radio button or check box, and has no effect on a push button.
void SetCheck( int nCheck );
用法:比如: ((CButton*)GetDlgItem(IDC_RADIO2))->SetCheck(false);
CToolBar::GetToolBarCtrl
This method allows direct access to the underlying common control.
Use GetToolBarCtrl to take advantage of both the functionality of the Windows CE toolbar common control and the support CToolBarCtrl provides for toolbar customization.
CToolBarCtrl& GetToolBarCtrl( )
const;
返回值:返回一个对CToolBarCtrl对象的引用。
说明:
此成员函数允许对基本通用控件的直接访问。
使用GetToolBarCtrl可以利用Windows工具条通用控件的性能,并且可以利用CToolBarCtrl为工具条定制提供的支持。
CToolBarCtrl::SetHotImageList
This method sets the image list that the toolbar control uses to display hot buttons. A button is hot when the pointer is above it.
CImageList* SetHotImageList( CImageList* pImageList );
例子:
CRect temp;
m_wndToolBar.GetItemRect(0,&temp); m_wndToolBar.GetToolBarCtrl()->SetButtonSize(CSize(temp.Width(), temp.Height()),CSize(16,15));