ITaskbarList3::ThumbBarSetImageList 方法(shobjidl_core.h)

指定一个图像列表,其中包含任务栏按钮浮出控件中窗口缩略图中嵌入的工具栏的按钮图像。

Syntax

HRESULT ThumbBarSetImageList(
  [in] HWND       hwnd,
  [in] HIMAGELIST himl
);

参数

[in] hwnd

类型:HWND

其缩略图表示形式包含要更新的工具栏的窗口的句柄。 此句柄必须属于调用进程。

[in] himl

类型: HIMAGELIST

包含工具栏中使用的所有按钮图像的图像列表的句柄。

返回值

类型:HRESULT

如果此方法成功,则返回 S_OK。 否则,它将返回 HRESULT 错误代码。

注解

应用程序必须提供以下按钮图像:

  • 处于默认活动状态的按钮。
  • 适合用于高 dpi(每英寸点数)显示器的图像。

映像必须为 32 位和维度 GetSystemMetrics(SM_CXICON) x GetSystemMetrics(SM_CYICON)。 工具栏本身为按钮的单击、禁用和悬停状态提供视觉对象。

Accessibility

在从图像列表中编制索引的 THUMBBUTTON 结构中提供的按钮图像可用于各种用户个性化方案。 常见示例是浅色和深色模式和辅助功能对比度主题。 选择在所有这些上下文中保持清晰可见的资产。

可以通过两种方式处理此问题:

例子

以下示例演示如何创建包含两个按钮的缩略图工具栏,其图像来自图像列表。


HRESULT AddThumbBarButtons(HWND hwnd, HIMAGELIST himl, HIMAGELIST himlHot)
{
    // Define an array of two buttons. These buttons provide images through an 
    // image list and also provide tooltips.
    DWORD dwMask = THB_BITMAP | THB_TOOLTIP | THB_FLAGS;
    
    THUMBBUTTON thbButtons[2];
    thbButtons[0].dwMask = dwMask;
    thbButtons[0].iId = 0;
    thbButtons[0].iBitmap = 0;
    thbButtons[0].pszTip = TEXT("Button 1");
    thbButtons[0].dwFlags = THBF_DISMISSONCLICK;

    dwMask = THB_BITMAP | THB_TOOLTIP;
    thbButtons[1].dwMask = dwMask;
    thbButtons[1].iId = 1;
    thbButtons[1].iBitmap = 1;
    thbButtons[1].pszTip = TEXT("Button 2");
    
    // Create an instance of ITaskbarList3
    ITaskBarList3 *ptbl;
    HRESULT hr = CoCreateInstance(CLSID_TaskbarList, 
                                  NULL, 
                                  CLSCTX_INPROC_SERVER, 
                                  IID_PPV_ARGS(&ptbl);

    if (SUCCEEDED(hr))
    {
        // Declare the image list that contains the button images.
        hr = ptbl->ThumbBarSetImageList(hwnd, himl);
        
        if (SUCCEEDED(hr))
        {
            // Attach the toolbar to the thumbnail.
            hr = ptbl->ThumbBarAddButtons(hwnd, ARRAYSIZE(thbButtons), &thbButtons);
        }
        ptbl->Release();
    }
    return hr;
}

要求

Requirement 价值
最低支持的客户端 Windows 7 [仅限桌面应用]
支持的最低服务器 Windows Server 2008 R2 [仅限桌面应用]
目标平台 Windows操作系统
Header shobjidl_core.h (包括 Shobjidl.h)
Library Explorerframe.lib
DLL Explorerframe.dll

另请参阅

ITaskbarList

ITaskbarList2

ITaskbarList3

ITaskbarList3::ThumbBarAddButtons

ITaskbarList3::ThumbBarUpdateButtons

任务栏扩展