TB_ADDBUTTONS訊息

將一或多個按鈕新增至工具列。

參數

wParam

要新增的按鈕數目。

lParam

TBBUTTON結構的陣列指標,其中包含要新增之按鈕的相關資訊。 陣列中的元素數目必須與 wParam指定的按鈕相同。

傳回值

如果成功,則傳回 TRUE ,否則傳回 FALSE

備註

如果使用 CreateWindowEx 函式建立工具列,您必須先將 TB_BUTTONSTRUCTSIZE 訊息傳送至工具列,才能傳送 TB_ADDBUTTONS

如需如何將點陣圖指派給一或多個影像清單中的工具列按鈕的討論,請參閱 TB_SETIMAGELIST

範例

下列範例程式碼會使用檢視按鈕的標準系統點陣圖,將三個按鈕新增至工具列。 TB_ADDBITMAP訊息會傳回影像清單中第一個按鈕影像的索引。 個別影像會以其與該值的位移來識別。

TBADDBITMAP tbAddBitmap;
tbAddBitmap.hInst = HINST_COMMCTRL;
tbAddBitmap.nID = IDB_VIEW_SMALL_COLOR;

// There are 12 items in IDB_VIEW_SMALL_COLOR.  However, because this is a standard
// system-defined bitmap, the wParam (nButtons) is ignored.
//
// hWndToolbar is the handle of the toolbar window.
//
// Do not forget to send TB_BUTTONSTRUCTSIZE if the toolbar was created
// by using CreateWindowEx.
//
int stdidx = SendMessage(hWndToolbar, TB_ADDBITMAP, 0, (LPARAM)&tbAddBitmap);

// Define the buttons. 
// IDM_SETLARGEICONVIEW and so on are application-defined command IDs.

const int numButtons = 3;
TBBUTTON tbButtonsAdd[numButtons] = 
{
    {stdidx + VIEW_LARGEICONS, IDM_SETLARGEICONVIEW, TBSTATE_ENABLED, BTNS_BUTTON},
    {stdidx + VIEW_SMALLICONS, IDM_SETSMALLICONVIEW, TBSTATE_ENABLED, BTNS_BUTTON},
    {stdidx + VIEW_DETAILS, IDM_SETDETAILSVIEW, TBSTATE_ENABLED, BTNS_BUTTON}
}; 

// Add the view buttons.
SendMessage(hWndToolbar, TB_ADDBUTTONS, numButtons, (LPARAM)tbButtonsAdd);

規格需求

需求
最低支援的用戶端
Windows Vista [僅限傳統型應用程式]
最低支援的伺服器
Windows Server 2003 [僅限桌面應用程式]
標頭
Commctrl.h
Unicode 與 ANSI 名稱
TB_ADDBUTTONSW (Unicode ) 和 TB_ADDBUTTONSA (ANSI)

另請參閱

工具列標準按鈕影像索引值