版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、在visual c+ 版本6中工具条的新特色(New features of toolbar in visual c+ version 6)Author: LHDate: 99-7-12 23:03:06New features of toolbar in Visual C+ version 6Author: Dave SchmittMicrosoft has launched the Visual C+6.0 preview for several months at /visualc. The official version is expected to
2、 be released by the end of this year. At the same time, the preview version shows that publication 6 will contain a lot of improvements and improvements, including supporting Internet controls, such as flat toolbars. Although the improved control package has nothing to do with Internet, it first app
3、ears in Internet Explorer, so it is taken as the name. In fact, the official preview version is titled preview of Visual C+ 5 technology for Internet Explorer 4.In the previous discussion on the MFC toolbar, I promised to provide an appearance demonstration of the toolbar in version 6. The good news
4、 is that all the work you do with CToolBar now works in the new version, including some of the extensions that were described in the previous column. As a result, youll easily modify existing programs to get cool interfaces like Internet Explorer and Visual Studio. Besides, theres no bad news.New fe
5、atures of toolbarAs early as version 4, CToolBar has been fully implemented by the MFC library. Once the public control dynamic link library (named comctl32.dll) becomes ubiquitous, CToolBar becomes synonymous with the toolbar controls that are now included in the operating system. However, CToolBar
6、 does not reveal all the capabilities of the utility toolbar control. Now, through the CreateEx () function, it succeeded.The public control dynamic link library now contains at least three styles: the original, added in Internet Explorer 3, and added in Internet Explorer 4. Although these versions
7、of the theory is compatible, but some professionals have been running the application cannot be written in later versions of the program, it is possible that these uses are not open functions, and these functions is not included in all versions.Visual C+ programmers have no such experience, because
8、in the comctl32.dll Visual C+4.0 or 5 is not a re distribution of components, it is updated in the installation of Internet Explorer, so MFC programmers can not rely on some features of the latest version for their program. Thats why CToolBar has only limited functionality of the original DLL. The l
9、atest feature of CToolBar means that Microsoft will include the latest DLL in Visual C+6.0 and use it as a component that can be redistributed.Most new features will be determined by a new style flag specified when calling CreateEx () and other CToolBar member functions. Here is a part of commctrl.h
10、, which defines the class identifier of TBSTYLE:#define TBSTYLE_BUTTON 0x0000#define TBSTYLE_SEP 0x0001#define TBSTYLE_CHECK 0x0002#define TBSTYLE_GROUP 0x0004#define TBSTYLE_CHECKGROUP (TBSTYLE_GROUP | TBSTYLE_CHECK)#if (_WIN32_IE = 0x0300)#define TBSTYLE_DROPDOWN 0x0008#endif#if (_WIN32_IE = 0x040
11、0)#define TBSTYLE_AUTOSIZE 0x0010#define TBSTYLE_NOPREFIX 0x0020#endif#define TBSTYLE_TOOLTIPS 0x0100#define TBSTYLE_WRAPABLE 0x0200#define TBSTYLE_ALTDRAG 0x0400#if (_WIN32_IE = 0x0300)#define TBSTYLE_FLAT 0x0800#define TBSTYLE_LIST 0x1000#定义tbstyle_customerase 0x2000# endif#如果(_win32_ie = 0x0400)#
12、定义tbstyle_registerdrop 0x4000#定义tbstyle_transparent 0x8000#定义tbstyle_ex_drawddarrows 0x00000001# endif你会注意到其中的一些采用了条件编译,依赖于_win32_ie的值,它缺省指的是Internet Explorer 4(即取值为0x0400)。对于Internet Explorer 3(即取值为0x0300)以前的版本,大多数的tbstyle标识符指的是按钮或是一组按钮。Internet Explorer 3引入了扁平钮、文本标签、下拉列表和自定义绘制。Internet Explorer 4增
13、强了下拉列表和自定义绘制功能,并且增加了支持OLE拖动目标到一个工具条。扁平钮和把手在过去的18个月中我常常被问及该如何获得象Internet Explorer和Visual Studio中的工具条一样不使用浮雕按钮而是用扁平钮并且带有便于移动和定位的把手那样酷的界面。这些特色并不被MFC所支持,因此最简单获取的方法就是购买一个扩展库。而对于Visual C+ 6来说却无须多此一举,因为它使得CToolBar类实现了对扁平钮、把手和其它新的视觉效果的支持。在预览版中,AppWizard并不会自动包括这些新特色,但它们却很容易被加入。表1显示了AppWizard创建的主框架窗口的oncreate
14、()函数,表2显示了需要做哪些修改以获得具有扁平钮和把手的工具条。图1显示了表1创建出的工具条,而图2显示出了表2实现的工具条。1:表CMainFrame OnCreate为AppWizard所产生int CMainFrame:onCreate(lpcreatestruct lpcreatestruct)如果(CMDIFrameWnd:onCreate(lpcreatestruct)= = 1)返回- 1;如果(!m_wndtoolbar创造(这| |)!m_wndtoolbar。LoadToolBar(idr_mainframe)trace0(“未能创建工具栏n”);返回1;/未能创建如果(
15、!m_wndstatusbar创造(这| |)。!m_wndstatusbar setindicators(指标,sizeof(指标图1表2:添加平面按钮和夹持器int CMainFrame:onCreate(lpcreatestruct lpcreatestruct)如果(CMDIFrameWnd:onCreate(lpcreatestruct)= = 1)返回- 1;如果(!m_wndtoolbar。CreateEx(这)| |!m_wndtoolbar。LoadToolBar(idr_mainframe)trace0(“未能创建工具栏n”);返回1;/未能创建如果(!m_wndstatu
16、sbar创造(这| |)。!m_wndstatusbar setindicators(指标,sizeof(指标)/ sizeof(个)trace0(“未能创建状态栏n”);返回1;/未能创建/ TODO:删除如果你不想要的工具提示或调整大小的工具栏m_wndtoolbar。setbarstyle(m_wndtoolbar getbarstyle() |。cbrs_gripper | cbrs_border_3d | cbrs_tooltips | cbrs_flyby | cbrs_size_dynamic);todo: / / delete these three lines if you
17、don t want to be the toolbar/ / in dockablem _ wndtoolbar.enabledocking (cbrs _ align _ any);enabledocking (cbrs _ align _ any);dockcontrolbar (a & m _ wndtoolbar);return 0;图2为了作出扁平按钮我必须使用createex 来代替create.这个新的函数在afxext.h中声明 () ():bool createex(cwnd * pparentwnd, / / parent windowdword dwctrlstyle
18、= tbstyle _ flat, / / extended styledword dwstyle = / / style_ child | ws ws _ visible | cbrs _ _ align topcrect rcborders = crect (0,0,0,0) / / border rectangleuint nid = afx _ idw _ toolbar / / identifier);因为扩展风格缺省指的就是tbstyle _ flat, 因此我要得到扁平按钮就只需要简单地将appwizard形成的代码中的create 改为createex 即可.我将在后面实现其它
19、的扩展风格 () ().为了获得把手, 我必须在调用setbarstyle () 函数时包含cbrs _ gripper标志, 参看表2.这是ccontrolbar类的一个新风格, 而ctoolbar类是从它继承而来的. 请注意到我也加入了cbrs _ border _ 3d标志, 这是为了修正一个未知的绘制问题, 该问题将会在工具条的边缘绘制一些多余的点.这也许意味着预览版确实有这个问题, 因为一旦我将3d标志加入就立即解决了并且也似乎没有影响到别的什么.上面所作的两个简单的改变是使得一个已存程序获得酷界面的最省力的方法.在一个程序具有了扁平钮和把手的同时, 它也不会发生不应有的其它改变.文
20、本标签internet explorer使得普通的工具条具有了大按钮和取代了文本提示的文本标签.mfc程序员可以通过setbuttontext (c + +) 函数为每个按钮设置一个文本串来获得这种效果.虽然在visual 5.0中已包含了这个函数, 但如果不使用扁平钮风格则不会取得令人满意的效果.表3显示了如何使用现有的文本提示作为按钮的标签, 而且图3和图4显示了将工具条分别定位在顶端和右边的效果.我仍然使得文本提示有效, 但你可以通过在调用setbarstyle () 时去掉cbrs _ tooltips风格而使之无效.表 3: adding text labels: (int cmai
21、nframe oncreate lpcreatestruct lpcreatestruct)if (cmdiframewnd: oncreate (lpcreatestruct) = = - 1)return - 1;if (! m _ wndtoolbar.createex | | (this). m _ wndtoolbar.loadtoolbar (idr _ mainframe)trace0 (failed to create toolbar i n );return - 1; / / fail to createif (! m _ wndstatusbar.create | | (t
22、his). m (_ wndstatusbar.setindicators indicators (indicators), sizeof / sizeof (uint)trace0 (failed to create status bar on n );return - 1; / / fail to create/ / todo: remove this if you don t want resizeable tool tips or the toolbar_ wndtoolbar.setbarstyle m (m _ wndtoolbar.getbarstyle () |cbrs _ g
23、ripper | cbrs _ border _ 3d | cbrs _ tooltips | cbrs _ flyby | cbrs _ _ dynamic size);/ / add text to each buttonFor (int i = 0; I m _ wndtoolbar.getcount (); I + +)uint id = m _ wndtoolbar.getitemid (I);CString s;If (! S.loadstring (ID) continue;Int j = s.find (_ t ( n);If (J 项)案例id_file_new:trace0
24、(“id_file_new下拉n”);/显示弹出菜单或列表框打破;/ TODO:添加下拉按钮等情况热点图像运行Internet Explorer 4并且将鼠标在工具条上划过。就能注意到在平时每个按钮是平淡的颜色。而当鼠标触及到该按钮时,他会凸出来并且显现出鲜艳的颜色。这种视觉效果采用了工具条控件的被称作”热点图像”的功能。一般的AppWizard代码使用工具条资源来指定其上按键的外观和与每个按键相连接的一个命令ID。工具条资源实际上包含一个复合的位图,该位图在调用loadtoolbar()函数时将被转变成一个图像列表(参见表4)。要激活热点图像功能,我必须通过sethotimagelist()
25、函数提供第二个图像列表,就象表6所示一样。表6:使用热图像int CMainFrame:onCreate(lpcreatestruct lpcreatestruct)如果(CMDIFrameWnd:onCreate(lpcreatestruct)= = 1)返回- 1;如果(!m_wndtoolbar。CreateEx(这)| |!m_wndtoolbar。LoadToolBar(idr_mainframe)trace0(“未能创建工具栏n”);返回1;/未能创建CImageList IMG;如果(!IMG创建(idb_mainframe,16,0,RGB(128128128)trace0(“无法加载热图像n”);返回-
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026年上海新云台中学初三下学期第5次月考生物试题含解析
- 2026年上交所未来产业沙龙6G连接空天地的数字底座核心观点盘点
- 2026届浙江省杭州市景成实验中学初三化学试题下学期开学考试试题含解析
- 2026届江苏省镇江市丹徒区、句容区初三下学期期末测试卷生物试题含解析
- 2026年基于客流动线的乡镇超市商品陈列与货架选型指南
- 2026年碳纤维PEEK等轻量化材料在人形机器人中的应用与成本优化方案
- 2025年临床执业《内科》阶段测试卷
- 通信设备公司技术支持面试全攻略
- 艺术画廊展览策划及实施步骤
- 酒店业商务经理职位的面试标准
- 国家安全概论-西安交通大学中国大学mooc课后章节答案期末考试题库2023年
- 检验检测机构资质认定评审准则释义
- YS/T 1018-2015铼粒
- GB/T 4450-1995船用盲板钢法兰
- GB/T 39489-2020全尾砂膏体充填技术规范
- GB/T 14598.301-2010微机型发电机变压器故障录波装置技术要求
- GB 30526-2019烧结墙体材料和泡沫玻璃单位产品能源消耗限额
- GA 139-2009灭火器箱
- 2023年江苏专转本计算机真题及答案
- 部编版小学道德与法治五年级下册第1课《读懂彼此的心》课件
- 医疗机构消防安全管理九项规定(2020版)-精品原创课件
评论
0/150
提交评论