Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Expand Minimize

TB_SETPRESSEDIMAGELIST message

Sets the image list that the toolbar uses to display buttons that are in a pressed state.

Parameters

wParam

The index of the image list. If you use only one image list, set this parameter to zero. See Remarks for details on using multiple image lists.

lParam

Handle to the image list to set. If this parameter is NULL, no images are displayed in the buttons.

Return value

Returns the handle to the image list previously used to display buttons in their pressed state, or NULL if no such image list was previously set.

Remarks

Note  Your application is responsible for freeing the image list after the toolbar is destroyed.

The TB_SETPRESSEDIMAGELIST message cannot be combined with TB_ADDBITMAP. It also cannot be used with toolbars created with CreateToolbarEx, which calls TB_ADDBITMAP internally. When you create a toolbar with CreateToolbarEx or use TB_ADDBITMAP to add images, the toolbar manages the image list internally. Attempting to modify it with TB_SETPRESSEDIMAGELIST has unpredictable consequences.

Button images need not come from the same image list. To use multiple image lists for your toolbar button images:

  1. Enable multiple image lists by sending the toolbar control a CCM_SETVERSION message with wParam (the version number) set to 5.
  2. For each image list you want to use, send the toolbar control a TB_SETPRESSEDIMAGELIST message. Set wParam to an application-defined wParam value that will be used to identify the list. Set lParam to the list's HIMAGELIST handle.
  3. For each button, set the iBitmap member of the button's TBBUTTON structure to MAKELONG(iIndex, iImageID). The iImageID value is the ID of the appropriate image list that was defined in step two. The iIndex value is the index of the particular image within that list.
  4. Add the buttons by sending the toolbar control a TB_ADDBUTTONS message.

The following code fragment illustrates how to add five buttons to a toolbar, with images from three different image lists. Support for multiple image lists is enabled with a CCM_SETVERSION message. The image lists are then set and assigned IDs of 0-2. The buttons are assigned images from the image lists as follows:

  • Button 0 is from image list zero (ahim[0]) with index of 1.
  • Button 1 is from image list one (ahim[1]) with an index of 1.
  • Button 2 is from image list two (ahim[2]) with an index of 1.
  • Button 3 is from image list zero (ahim[0]) with an index of 2.
  • Button 4 is from image list one (ahim[1]) with an index of 3.

Finally, the buttons are added to the toolbar control with a TB_ADDBUTTONS message.


// Enable multiple image lists
    SendMessage(hwndTB, CCM_SETVERSION, (WPARAM) 5, 0); 

    //Set the image lists and assign them IDs of 0-2
    SendMessage(hwndTB, TB_SETPRESSEDIMAGELIST, 0, (LPARAM)ahiml[0]);
    SendMessage(hwndTB, TB_SETPRESSEDIMAGELIST, 1, (LPARAM)ahiml[1]);
    SendMessage(hwndTB, TB_SETPRESSEDIMAGELIST, 2, (LPARAM)ahiml[2]);

    // Create the five buttons
    TBBUTTON rgtb[5];
	
    //... initialize the TBBUTTON structures as usual ...
	
    //Assign images to each button
    rgtb[0].iBitmap = MAKELONG(1, 0);
    rgtb[1].iBitmap = MAKELONG(1, 1);
    rgtb[2].iBitmap = MAKELONG(1, 2);
    rgtb[3].iBitmap = MAKELONG(2, 0);
    rgtb[4].iBitmap = MAKELONG(3, 1);

    // Add the five buttons to the toolbar control
    SendMessage(hwndTB, TB_ADDBUTTONS, 5, (LPARAM)(&rgtb);

Requirements

Minimum supported client

Windows Vista [desktop apps only]

Minimum supported server

Windows Server 2008 [desktop apps only]

Header

Commctrl.h

See also

Reference
TB_GETPRESSEDIMAGELIST
Other Resources
MAKELONG

 

 

Community Additions

ADD
Show:
© 2015 Microsoft