为什么我不能使用DwmSetIconicThumbnail在任务栏上设置缩略图?

时间:2019-05-03 15:10:10

标签: c++ windows taskbar

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

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

但是当前的问题是在选项卡上没有设置缩略图。

给定的参数是主软件中窗口的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?

感谢所有将解决我的问题的人。 这是我的第一个问题,请友善:)

0 个答案:

没有答案