c++ - 为什么我不能使用 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 ?
感谢所有会照顾我的问题的人。这是我的第一个问题,请友好:)
解决方案
推荐阅读
- javascript - 与天气命令混淆,我该如何解决?
- javascript - 如何在 ajax 调用中在 request.body 上发送数据?
- python - 无法导入“从 google.cloud 导入 bigquery”
- docker - 如何在 Kubernetes 上运行 e2e 测试之前/期间通过我的 Docker 凭据
- javascript - 如何从远程切换到 ipcMain 和 ipcRenderer?
- java - Play Framework 2.8.8 "play-java-jpa-example" 抛出 JsTaskFailure: Wrapped java.lang.ArrayIndexOutOfBoundsException (module.js#439)
- android - 升级到 ktor 1.5.4 时导致此 ArrayIndexOutOfBoundsException 的原因是什么?
- python - PySpark 中 pandas.cut() 的等价物是什么?
- sql - 在此查询中获取 1 和 0 而不是 COUNT
- excel - 包含特殊词的过滤器