通过载入bitmap来设置ctoolbar

本文介绍了如何在Windows应用程序中通过加载位图来创建和设置CToolBar。首先,创建并初始化CToolBar对象,然后调用LoadBitmap加载包含按钮图像的位图资源。接下来,使用SetButtons设置按钮样式和关联的图像。位图中的所有图像必须具有相同的尺寸,并按顺序对应到按钮。文章还提到了如何改变按钮风格和状态,以及对256色位图的处理方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

参见msdn--------------------------------------------

Visual C++ provides you with two methods to create a toolbar. To create a toolbar resource using the Resource Editor, follow these steps:

  1. Create a toolbar resource.
  2. Construct the CToolBar object.
  3. Call the Create (or CreateEx) function to create the Windows toolbar and attach it to the CToolBar object.
  4. Call LoadToolBar to load the toolbar resource.

Otherwise, follow these steps:

  1. Construct the CToolBar object.
  2. Call the Create (or CreateEx) function to create the Windows toolbar and attach it to the CToolBar object.
  3. Call LoadBitmap to load the bitmap that contains the toolbar button images.
  4. Call SetButtons to set the button style and associate each button with an image in the bitmap.

All the button images in the toolbar are taken from one bitmap, which must contain one image for each button. All images must be the same size; the default is 16 pixels wide and 15 pixels high.(可以设任意大小) Images must be side by side in the bitmap.

The SetButtons function takes a pointer to an array of control IDs and an integer that specifies the number of elements in the array. The function sets each button’s ID to the value of the corresponding element of the array and assigns each button an image index, which specifies the position of the button’s image in the bitmap. If an array element has the value ID_SEPARATOR, no image index is assigned.

不用去管分隔条,图片ID依次

The order of the images in the bitmap is typically the order in which they are drawn on the screen, but you can use the SetButtonInfo function to change the relationship between image order and drawing order.

All buttons in a toolbar are the same size. The default is 24 x 22 pixels, in accordance with Windows Interface Guidelines for Software Design. Any additional space between the image and button dimensions is used to form a border around the image.

Each button has one image. The various button states and styles (pressed, up, down, disabled, disabled down, and indeterminate) are generated from that one image. Although bitmaps can be any color, you can achieve the best results with images in black and shades of gray.

Toolbar buttons imitate pushbuttons by default. However, toolbar buttons can also imitate check-box buttons or radio buttons. Check-box buttons have three states: checked, cleared, and indeterminate. Radio buttons have only two states: checked and cleared.

To set an individual button or separator style without pointing to an array, call GetButtonStyle to retrieve the style, and then call SetButtonStyle instead of SetButtons. SetButtonStyle is most useful when you want to change a button’s style at run time.

 

 

2.还有一种方法,不过仅仅支持不大于256色(<=256色),但是在vc上效果还是会失真

(1)先载入bmp图片资源(<=256)

(2)VC菜单---Image---Grid Settings(设置工具条要怎么分割图像)

(3)VC菜单---Image---Tool Bar editor(会自动转换为Tool Bar的资源)

(4)载入图片-OK

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值