我想获取 Windows 桌面壁纸的位图数据。而且,我想直接在位图上绘制一些文本。
首先,我尝试通过以下代码获取位图数据。
#include <windows.h>
#include <Commctrl.h>
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrev,
LPSTR cmdLine, int showCmd)
{
CoInitialize(NULL);
// find Progman
HWND hProgman = FindWindow("Progman", "Program Manager");
// find DefView
HWND hDefView = FindWindowEx(hProgman, NULL, "SHELLDLL_DefView", NULL);
// find SysListView
HWND hListView = FindWindowEx(hDefView, NULL, "SysListView32", NULL);
char filename[512] = {0};
LVBKIMAGE lvbki;
lvbki.ulFlags = LVBKIF_SOURCE_HBITMAP;
lvbki.hbm = NULL;
lvbki.pszImage = filename;
lvbki.cchImageMax = 512;
lvbki.xOffsetPercent = 0;
lvbki.yOffsetPercent = 0;
int ret = ListView_GetBkImage(hListView, &lvbki);
if (ret == 0) {
MessageBox(NULL, TEXT("GetBkImage failed!"), TEXT("err"), 0);
return -1;
}
if (lvbki.hbm == NULL){
MessageBox(NULL, TEXT("hbm is NULL"), TEXT("err"), 0);
return -1;
}
MessageBox(NULL, TEXT("FINISHED"), TEXT("msg"), 0);
CoUninitialize();
return 0;
}
此代码的结果是“hbm 为 NULL”。是错误的代码吗?
我的问题是如何获取在 SysListView32 上显示为桌面墙纸的位图数据?而且,有可能吗?
问候。