如何在创建后更改工具栏按钮样式? [英] How do I change a tool bar button style after creation?

查看:85
本文介绍了如何在创建后更改工具栏按钮样式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码段是MFC应用程序的OnCreate Handler的一部分,其启动代码由向导生成。

(代码格式不正确。我从未见过问题格式代码栏,当我尝试再发一个问题时)。





 m_wndToolBar是键入CMFCToolBar。 


int CMainFrame :: OnCreate(LPCREATESTRUCT lpCreateStruct)
{





if (!m_wndToolBar.CreateEx( this ,TBSTYLE_FLAT,WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC)||
!m_wndToolBar.LoadToolBar(theApp.m_bHiColorIcons?IDR_MAINFRAME_256:IDR_MAINFRAME))
{
TRACE0( 无法创建工具栏\ n);

HCURSOR hCursor = AfxGetApp() - > LoadStandardCursor(IDC_ARROW);
SetCursor(hCursor);
返回 - 1 ; // 无法创建
}

// 我尝试添加分隔符并更改按钮样式但没有发生任何事情
int iCount = m_wndToolBar.GetCount();
m_wndToolBar.InsertSeparator( 8 );

for int i = 9 ; i< iCount; i ++)
{
m_wndToolBar.SetButtonStyle(i,TBBS_SEPARATOR);
}





}

解决方案

早些时候我遇到了很多麻烦,所以我的经验是你最好重新创建工具栏。



我这样做主要是创建工具栏 WITH ALL FEATURES ,并删除了不想要的东西。



这是一些代码,但是:它有效。 ; - )

The following code segment is part of the OnCreate Handler of an MFC application whose starting codes were generated by wizard.
(The code is not well formatted. I don't ever see the Question Formating code bar when I try to post a question any longer).


m_wndToolBar is a member of type CMFCToolBar.


int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
     .
     .
     .
     .

     if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
		!m_wndToolBar.LoadToolBar(theApp.m_bHiColorIcons ? IDR_MAINFRAME_256 : IDR_MAINFRAME))
	{
		TRACE0("Failed to create toolbar\n");

		HCURSOR hCursor = AfxGetApp()->LoadStandardCursor(IDC_ARROW); 
		SetCursor(hCursor);
		return -1;      // fail to create
	}
        
     //I attempted to add a separator and change button style but nothing happened
	int iCount = m_wndToolBar.GetCount();
	m_wndToolBar.InsertSeparator(8);

	for(int i = 9; i < iCount; i++)
	{
		m_wndToolBar.SetButtonStyle(i,TBBS_SEPARATOR);
	}
        .
        .
        .
        .
        .
}

解决方案

In earlier times I got lots of trouble with that, so my experience is that you better re-create the toolbar.

I had done this mostly be creating the toolbar WITH ALL FEATURES, and deleted the un-wanted stuff.

It is some code, but: it works. ;-)


这篇关于如何在创建后更改工具栏按钮样式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆