(, 下载次数: 1)
实现这功能非常简单,只要通过简单调用CToolBar内部几个成员函数便可,其中重要几个函数。我们这里另外使用小技巧实现;
void SetSizes( SIZE sizeButton, SIZE sizeImage );
void SetHeight( int cyHeight );
BOOL SetButtonText( int nIndex, LPCTSTR lpszText );
•1.新建一个对话框应用程序
•2.在对话框类中添加几个变量
•BOOL m_bShowText; //显示隐藏工具栏按钮文本标识
• CToolBar m_ToolBar; //带文本的工具栏
• CToolBar m_ToolBar1; //仅带图标的工具栏
• CImageList m_ImageList;
•3.在对话框类的OnInitDialog()中对这些变量进行初始化
• m_ImageList.Create(16,16,ILC_COLOR24|ILC_MASK,1,1);
• m_ImageList.Add(AfxGetApp()->LoadIcon(IDI_ICON1));
• m_ImageList.Add(AfxGetApp()->LoadIcon(IDI_ICON2));
• m_ImageList.Add(AfxGetApp()->LoadIcon(IDI_ICON3));
• m_ImageList.Add(AfxGetApp()->LoadIcon(IDI_ICON4));
• m_ImageList.Add(AfxGetApp()->LoadIcon(IDI_ICON5));
• m_ImageList.Add(AfxGetApp()->LoadIcon(IDI_ICON6));
• m_ImageList.Add(AfxGetApp()->LoadIcon(IDI_ICON7));
• m_ImageList.Add(AfxGetApp()->LoadIcon(IDI_ICON8));
• UINTarray[11];
• for(inti=0;i<11;i++)
• {
• if(i==3|| i==7 || i==9)
• array= ID_SEPARATOR; //设置ID 第4、8、10个按钮为分隔条
• else
• array= i+1001;
• }
• CStringstr[]={"新建","打开","保存","","剪切","复制","粘贴","","打印","","退出"};
• m_ToolBar.CreateEx(this,TBSTYLE_FLAT,WS_CHILD| WS_VISIBLE | CBRS_TOP
• |CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_SIZE_DYNAMIC | CBRS_BORDER_TOP );
• m_ToolBar1.CreateEx(this,TBSTYLE_FLAT,WS_CHILD| WS_VISIBLE | CBRS_TOP
• |CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_SIZE_DYNAMIC | CBRS_BORDER_TOP );
• m_ToolBar.SetButtons(array,11);
• m_ToolBar1.SetButtons(array,11);
• for(i=0;i<11;i++)
• {
• m_ToolBar.SetButtonText(i,str); //设置工具栏按钮文本
• m_ToolBar1.SetButtonText(i,"");
• }
演示功能实现的整个过程
[iqiyi]http://player.video.qiyi.com/484eb2fd9971a26d76fce37c88c33878/0/0/w_19rt94bj2t.swf-albumId=4866468409-tvId=4866468409-isPurchase=0-cnId=12[/iqiyi]
源码及视频下载
(仅在电脑可见)