现在的位置: 首页 > 综合 > 正文

通过载入bitmap来设置ctoolbar

2013年02月06日 ⁄ 综合 ⁄ 共 3436字 ⁄ 字号 评论关闭

参见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

抱歉!评论已关闭.