通过载入bitmap来设置ctoolbar

//工具栏TBSTYLE_FLAT if (!m_wndToolBar.CreateEx(this, TBSTYLE_CUSTOMERASE, WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC))//载入工具栏IDR_MAINFRAME { TRACE0("Failed to create toolbar window/n"); return -1; } SIZE szButton; szButton.cx = 24; szButton.cy = 24; SIZE szImage; szImage.cx = 17; szImage.cy = 16; m_wndToolBar.SetSizes(szButton, szImage); if (! m_wndToolBar.LoadBitmap(IDB_BITMAP_MENU)) { TRACE0("Failed to LoadBitmap/n"); return -1; } UINT arButtonCommandID[14]; arButtonCommandID[0] = ID_TDEV_IN; arButtonCommandID[1] = ID_TDEV_OUT; arButtonCommandID[2] = ID_TDEV_TEMPLATE; arButtonCommandID[3] = ID_SEPARATOR; arButtonCommandID[4] = ID_TDEV_MAINTAIN; arButtonCommandID[5] = ID_TDEV_DEL; arButtonCommandID[6] = ID_TSTART_CHECK; arButtonCommandID[7] = ID_SEPARATOR; arButtonCommandID[8] = ID_TCUSTOM_SLT; arButtonCommandID[9] = ID_TMANAGE_SLT; arButtonCommandID[10] = ID_TMANAGE_THRESHOLD; arButtonCommandID[11] = ID_TMANAGE_TASK; arButtonCommandID[12] = ID_SEPARATOR; arButtonCommandID[13] = ID_THELP; m_wndToolBar.SetButtons(arButtonCommandID, 14); m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);

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

你可能感兴趣的:(通过载入bitmap来设置ctoolbar)