【工具栏的背景色】

2023-07-08 14:22:42 浏览数 (1)

代码语言:javascript复制
int CArxMsgHandler::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
 //   if (CWnd::OnCreate(lpCreateStruct) == -1)
 //       return -1;   
 //   // 创建工具栏
 //   m_pToolbar = CreateToolBar(IDR_TOOLBAR1, this, _T("工具栏"));
 //   m_pToolbar->AddButtonFromMenu(IDR_MENU1);
 //  
	//for (int i=0;i<m_pToolbar->GetToolBarCtrl().GetButtonCount();i  )
	//{
	//	CRect rect;
	//	m_pToolbar->GetToolBarCtrl().GetItemRect(i,rect);
	//	m_pToolbar->SetSizes(CSize(rect.Width(),rect.Height()),CSize(0, 0));
	//	m_pToolbar->SetButtonStyle(i,TBSTYLE_AUTOSIZE|TBSTYLE_DROPDOWN);

	//}
	//acedGetAcadFrame()->RecalcLayout(FALSE);
	//acedGetAcadFrame()->DockControlBar(m_pToolbar);
 //   return 0;

	if (CWnd::OnCreate(lpCreateStruct) == -1)
        return -1;   
    // 创建工具栏
    m_pToolbar = CreateToolBar(IDR_TOOLBAR, this, _T("工具栏"));
    //m_pToolbar->AddButtonFromMenu(IDR_MENU1);
	nCurrToolBarBtn=-1;
#if 0
#endif
	//std::vector<CString> lines1;
	//std::vector<CString> menuLines1;
	std::vector<int> num;
	if (!menuEx.m_hMenu)
	{
		menuEx.CreateMenu();
		AddMenuTextFromTextLine(lines,menuLines,num,mList);
		for (int i=0;i<m_mapLinesData.size();i  ){
			
			AddMenuTextFromTextLine(lines,m_mapLinesData[i].m_MenuStart,m_mapLinesData[i].m_MenuEnd,m_mapLinesData[i].m_Menuid,menuEx,menuLines[i]);	

		}
	}

	
	m_pToolbar->AddButtonFromVector(menuLines);
	//m_pToolbar->AddButtonFromText(lines1,menuLines1,num);
	//if (menuEx.m_hMenu)
	//{
	//	//m_pToolbar->AddButtonFromMenu1(menuEx);
	//	acutPrintf(_T("菜单出现"));
	//}
	
	 CRect rect;
	 GetClientRect(&rect);                         //计算客户区大小  
	 m_pToolbar->MoveWindow(0, 0, rect.Width(), 25);
	 DWORD dwStyle = m_pToolbar->GetButtonStyle(m_pToolbar->CommandToIndex(IDR_TOOLBAR1));
	 dwStyle |= TBSTYLE_DROPDOWN; //其中ID_DRAW_LINE是你要添加下拉菜单的按钮的ID
		//m_pToolbar->GetButtonStyle()
	 m_pToolbar->SetButtonStyle(m_pToolbar->CommandToIndex(ID_BUTTON1), dwStyle);
	 m_pToolbar->SetButtonStyle(m_pToolbar->CommandToIndex(ID_32769), dwStyle);
	 m_pToolbar->SetButtonStyle(m_pToolbar->CommandToIndex(ID_32770), dwStyle);
	 m_pToolbar->SetButtonStyle(m_pToolbar->CommandToIndex(ID_32771), dwStyle);
	for (int i=0;i<m_pToolbar->GetToolBarCtrl().GetButtonCount();i  )
	{
		CRect rect;
		m_pToolbar->GetToolBarCtrl().GetItemRect(i,rect);
		m_pToolbar->SetSizes(CSize(rect.Width(),rect.Height()),CSize(0, 0));
		m_pToolbar->SetButtonStyle(i,TBSTYLE_AUTOSIZE|TBSTYLE_DROPDOWN);

	}
	CRect rect;
	GetClientRect(rect);
	rect.bottom = rect.top   40;
	// 创建一个伸缩条并在其中添加菜单栏
	/*if (!m_wndReBar.Create(WS_CHILD | WS_VISIBLE | RBS_BANDBORDERS | WS_BORDER | RBS_AUTOSIZE | RBS_VARHEIGHT, rect, m_pToolbar, 10))
	{
		TRACE0("n未能创建伸缩条n");
		return -1;
	}*/
	m_wndReBar.Create(this);//创建窗口(控件)
	//m_wndReBar.AddBar(m_pToolbar->mpOwner,0, RGB(240, 240, 240));//添加m_Toolbar为子窗口
	m_wndReBar.AddBar(pgArxMsgHandler->m_pToolbar, RGB(240, 240, 240), RGB(240, 240, 240));//添加m_Toolbar为子窗口
	
	m_wndReBar.RedrawWindow();//重画窗口
	REBARBANDINFO info;
	info.cbSize = sizeof(info);
	//info.fMask = RBBIM_BACKGROUND;
	info.fMask = RBBIM_COLORS;
	//m_pToolbar->ModifyStyle(0, TBSTYLE_TRANSPARENT);//设置工具栏背景色透明
	//info.hbmBack = LoadBitmap(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDR_TOOLBAR));//加载位图
	info.clrBack = RGB(240, 240, 240);
	m_wndReBar.GetReBarCtrl().SetBandInfo(0, &info);
 	acedGetAcadFrame()->RecalcLayout(FALSE);
	acedGetAcadFrame()->DockControlBar(m_pToolbar);
    return 0;
}

头文件

代码语言:javascript复制
CReBar m_wndReBar;

不好用,没有改变工具栏的背景色

0 人点赞