none
how to change the backcolor of a ToolBar?help!! RRS feed

  • 问题

  • I create a tool bar,I Create serval button on it,and button has it's bitmap,

    this code is in function OnInitDialog(void)

    if(!m_toolbar2.Create(this))  
    {
    MessageBox(TEXT("Error In Create "));
    }

    m_list.Create(48,48,/*ILC_COLORDDB*/ILC_COLOR32/*|ILC_MASK*/,1,1);
    m_list.Add(AfxGetApp()->LoadIcon(IDI_ICON1));
    //m_list.Add(&m_bitmap,RGB(0,0,255));
    m_list.Add(AfxGetApp()->LoadIcon(IDI_ICON2));
    m_list.Add(AfxGetApp()->LoadIcon(IDI_ICON3));
    m_list.Add(AfxGetApp()->LoadIcon(IDI_ICON4));
    m_list.Add(AfxGetApp()->LoadIcon(IDI_ICON5));
    m_list.Add(AfxGetApp()->LoadIcon(IDI_ICON6));
    m_list.Add(AfxGetApp()->LoadIcon(IDI_ICON7));
    m_toolbar2.GetToolBarCtrl().SetImageList(&m_list);

    it do well,and i can see the toolbar show perfectly;

    when i change the backcolor of the dialog,the backcolor of toolbar is still gray(system color),it see so bad,so i want dervie a new class from CToolBar ,i named CExToolBar and I make the OnEraseBkGnd funtion return true,so the problem is solved,but another problem occured.the back of the toolbar  can't erase when i need it erase!

    so who can solve my problem,i am confused about it some time!

    HELP!!!

    2012年2月25日 11:04

全部回复

  • In CMainFrame class, Add OnNotify virtual function.

    BOOL CMainFrame::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult) 
    {
    	// TODO: Add your specialized code here and/or call the base class
    	LPNMHDR pnmh = (LPNMHDR) lParam;
    	if(pnmh->hwndFrom == m_wndToolBar.m_hWnd)
    	{
    		LPNMTBCUSTOMDRAW lpNMCustomDraw = (LPNMTBCUSTOMDRAW) lParam;
    		CRect rect;
    		m_wndToolBar.GetClientRect(rect);
    		FillRect(lpNMCustomDraw->nmcd.hdc, rect, (HBRUSH)GetStockObject(BLACK_BRUSH));
    		
    	}
    
    	return CFrameWnd::OnNotify(wParam, lParam, pResult);
    }


    Visual C++ enthusiast, like network programming and driver development. At present is being engaged in the WinCE/Windows Mobile platform embedded development.

    2012年2月25日 13:57
    版主
  • 'Visual C++ enthusiast, like network programming and driver development. At present is being engaged in the WinCE/Windows Mobile platform embedded development.' what do you mean?many people say  mfc is  out of fashion.but i am good at C++,so i want to konw more about mfc

    2012年2月27日 15:28