2

这是来自 MSDN 的用于创建工具栏的代码。我做了一些修改以使用自定义图标。

HWND hToolbar = CreateWindowEx(0, TOOLBARCLASSNAME, 0, 
    TBSTYLE_FLAT | CCS_ADJUSTABLE | CCS_NODIVIDER | WS_CHILD | WS_VISIBLE | TBSTYLE_WRAPABLE,
    0, 0, 0, 0, hwnd, (HMENU)ID_TOOLBAR, g_hInstance, 0);
if ( !hToolbar )
    return FALSE;

SendMessage(hToolbar, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0);

const int numButtons = 12;

HIMAGELIST hImageList = ImageList_Create(16, 16, ILC_COLOR16 | ILC_MASK, numButtons, 0);
SendMessage(hToolbar, TB_SETIMAGELIST, (WPARAM)0, (LPARAM)hImageList);
SendMessage(hToolbar, TB_LOADIMAGES, (WPARAM)IDB_STD_SMALL_COLOR, (LPARAM)HINST_COMMCTRL);

TBBUTTON tbButtons[numButtons] = 
{
             // IDI_ICON1 - the custom icon
    { MAKELONG(0, 0), IDI_ICON1, TBSTATE_ENABLED,
    BTNS_AUTOSIZE, {0}, 0, (INT_PTR)L"Add Download" }
};
SendMessage(hToolbar, TB_ADDBUTTONS, numButtons, (LPARAM)tbButtons);

SendMessage(hToolbar, TB_AUTOSIZE, 0, 0);

但是没有显示自定义图标。它只是空白。如果需要,我会发布屏幕截图。我究竟做错了什么?提前致谢。

4

0 回答 0