您现在的位置: 中国教师站 >> 教师关注 >> 电脑技术 >> 编程技术 >> Visual C >> 正文

Google
Toolbars
作者:Siny 文章来源:中国教师站cn-teacher 点击数: 更新时间:2007-4-22 13:05:32

Toolbars

A toolbar's purpose is to provide one-click access to commonly used commands. Toolbar buttons typically serve as shortcuts for menu commands, but they can also implement commands that don't appear in a menu. MFC's CToolBar class takes a bitmap resource containing images for the faces of the toolbar buttons and an array of button IDs and creates a toolbar object that docks to the side of a frame window or floats in its own mini frame window. Toolbar buttons are assigned command IDs just as menu items are. Clicking a toolbar button produces a WM_COMMAND message just as if a menu item had been selected. If a menu item and a toolbar button are assigned the same command ID, one command handler can serve them both. With a little work, you can add combo boxes, check boxes, and other non-push-button controls to a toolbar. You can also convert ordinary push buttons into "check push buttons" that stay up or down when clicked or "radio push buttons" that work like radio buttons. MFC provides functions for hiding and displaying toolbars, saving and restoring toolbar states, and much more.

In early versions of MFC, CToolBar was a stand-alone class whose functionality came entirely from MFC. Today, CToolBar derives much of its functionality from the toolbar control in Comctl32.dll. A separate and more primitive MFC class named CToolBarCtrl provides an MFC interface to toolbar controls. That's useful to know, because if you want to do something with a CToolBar and can't find a suitable member function, CToolBarCtrl might have the member function you're looking for. You can call CToolBarCtrl functions on a CToolBar if you first call CToolBar::GetToolBarCtrl to acquire a CToolBarCtrl reference to the underlying control. Most of the time, however, CToolBar will do everything you need and then some. With that in mind, let's see what it takes to get a CToolBar up and running.

Creating and Initializing a Toolbar

You create a toolbar by constructing a CToolBar object and calling CToolBar::Create. Because a toolbar is a child of the application's main frame window and is normally created when the frame window is created, the usual practice is to add a CToolBar member to the frame window class and call Create from the frame window's OnCreate handler. If m_wndToolBar is a CToolBar data member, the statement

m_wndToolBar.Create (this);

creates a toolbar that is a child of this. Two parameters are implicit in the call: the toolbar's style and its child-window ID. The default style is WS_CHILD ¦ WS_VISIBLE ¦ CBRS_TOP. You can change the toolbar style by adding a second parameter to Create or by calling the SetBarStyle function that a toolbar inherits from its base class, CControlBar, after the toolbar is created. For example, to replace CBRS_TOP with CBRS_BOTTOM so that the toolbar aligns itself along the bottom of its parent, you could create it like this:

m_wndToolBar.Create (this, WS_CHILD ¦ WS_VISIBLE ¦ CBRS_BOTTOM);

Or you could create it like this:

m_wndToolBar.Create (this);m_wndToolBar.SetBarStyle ((m_wndToolBar.GetBarStyle () &    ~CBRS_TOP) ¦ CBRS_BOTTOM);

CToolBar::Create also accepts an optional third parameter specifying the toolba

[1] [2] [3] [4] [5] [6] [7] [8] [9] [10]  ... 下一页  >> 

  • 上一篇文章:

  • 下一篇文章:
  • 相关专题:
     
     网友评论:(评论内容只代表网友观点,与本站立场无关!)
    GOOGLE广告

    阅读排行

    | 设为首页 | 加入收藏 | 联系站长 | 友情链接 | 版权申明 |
    中国教师站

    中国教师站 版权所有 Copyright © 2006-2020 All Rights Reserved 站长:Sina & Siny
    [备用域名:www.JXZYW.Com] 有事请留言有事请留言
    【实力成就精品 诚信呵护品牌】

    信息产业部备案
    苏ICP备06018635号