首页 > 解决方案 > 为什么我不能使用 DwmSetIconicThumbnail 在任务栏上设置缩略图?

问题描述

我工作中的一个项目需要你的帮助。主软件使用 4D 语言,作为 MDI 工作,它创建了许多包含在主窗口中的窗口。主要问题是我们有很多窗口,我们需要一种简单的方法从一个窗口切换到另一个窗口。我们决定创建一个小的 c++ 插件,它是一个 dll 来解决这个问题。

该插件将为每个打开的窗口(如 Windows 资源管理器)在任务栏上创建一个选项卡。选项卡的创建和删除已经有效。

但是目前的问题是Tab上没有设置缩略图。

给出的参数是来自主软件的窗口的 ID。调用PA_GetHWND的方法是 4D 给出的使用windowID. 我已经检查了问题出在哪里。从窗口创建的位图已经存在并且很好。对于这个测试,我将位图放在剪贴板中并将其粘贴到 Paint 上,位图很好。

这是介绍刷新选项卡上的位图的方法的代码。

bool CManageTaskBar::UpdateWindow(long WindowID) 
{

    HRESULT res;
    HDC hdcScreen;
    HDC hdcWindow;
    HDC hdcMemDC = NULL;
    HBITMAP hbmScreen = NULL;

    //Get the Handle from 4D
        HWND nHandle = (HWND)(PA_GetHWND((PA_WindowRef)(WindowID)));

    // Retrieve the handle to a display device context for the client 
    // area of the window. 
    hdcScreen = GetDC(NULL);
    hdcWindow = GetDC(nHandle);

    // Create a compatible DC which is used in a BitBlt from the window DC
    hdcMemDC = CreateCompatibleDC(hdcWindow);

    // Get the client area for size calculation
    RECT rcClient;
    GetClientRect(nHandle, &rcClient);

    // Create a compatible bitmap from the Window DC
    hbmScreen = CreateCompatibleBitmap(hdcWindow,rcClient.right - rcClient.left, rcClient.bottom - rcClient.top);

    // Select the compatible bitmap into the compatible memory DC.
    SelectObject(hdcMemDC, hbmScreen);

    // Bit block transfer into our compatible memory DC.
    if (!BitBlt(hdcMemDC,
        0, 0,
        rcClient.right - rcClient.left, rcClient.bottom - rcClient.top,
        hdcWindow,
        0, 0,
        SRCCOPY))
    {
        MessageBox(nHandle, L"BitBlt has failed", L"Failed", MB_OK);
        //goto done;
    }

    ITaskbarList3* ptbl = NULL;
    HRESULT hr = CoCreateInstance(my_CLSID_TaskbarList, NULL, CLSCTX_ALL, my_IID_ITaskbarList3, (LPVOID*)&ptbl);


    BOOL fForceIconic = TRUE;
    BOOL fHasIconic = TRUE;
    res = DwmSetWindowAttribute(nHandle, DWMWA_FORCE_ICONIC_REPRESENTATION, &fForceIconic, sizeof(fForceIconic));
    res = DwmSetWindowAttribute(nHandle, DWMWA_HAS_ICONIC_BITMAP, &fHasIconic, sizeof(fHasIconic));

    if (hbmScreen)
    {
        res = DwmSetIconicThumbnail(nHandle, hbmScreen,0);//DWM_SIT_DISPLAYFRAME);
    }

    DeleteObject(hbmScreen);
    DeleteObject(hdcMemDC);
    ReleaseDC(NULL, hdcScreen);
    ReleaseDC(nHandle, hdcWindow);

    return true;
}

DwmSetWindowAttribute返回无效句柄的调用。此句柄用于获取位图但不能设置属性。

并且调用DwmSetIconicThumbnail返回E_INVALIDARG可能是因为给定的句柄是错误的。

为什么我不能为这个句柄设置一个属性,为什么设置缩略图的调用返回 E_INVALIDARG ?

感谢所有会照顾我的问题的人。这是我的第一个问题,请友好:)

标签: c++windowstaskbar

解决方案


推荐阅读