我知道这是一个很晚的答案,但我最近自己研究了一下,如果其他用户有同样的问题,这可能会对他们有所帮助。
注意:此答案适用于 C++,但也许它可以帮助您在 C# 中做同样的事情
正如上面评论中提到的,我跟随This guide了解我将如何打开 windows 壁纸窗口。
通过使用这两种方法:
BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam) {
HWND p = FindWindowEx(hwnd, NULL, "SHELLDLL_DefView", NULL);
HWND* ret = (HWND*)lParam;
if (p)
{
// Gets the WorkerW Window after the current one.
*ret = FindWindowEx(NULL, hwnd, "WorkerW", NULL);
}
return true;
}
HWND get_wallpaper_window() {
// Fetch the Progman window
HWND progman = FindWindow("ProgMan", NULL);
// Send 0x052C to Progman. This message directs Progman to spawn a
// WorkerW behind the desktop icons. If it is already there, nothing
// happens.
SendMessageTimeout(progman, 0x052C, 0, 0, SMTO_NORMAL, 1000, nullptr);
// We enumerate all Windows, until we find one, that has the SHELLDLL_DefView
// as a child.
// If we found that window, we take its next sibling and assign it to workerw.
HWND wallpaper_hwnd = nullptr;
EnumWindows(EnumWindowsProc, (LPARAM)&wallpaper_hwnd);
// Return the handle you're looking for.
return wallpaper_hwnd;
}
我能够检索到 Windows 句柄。
由于我只熟悉 SDL,这是我找到的唯一解决方案,但我相信任何允许您基于另一个窗口创建/修改窗口的方法都应该有效。
window = SDL_CreateWindowFrom((void*)get_wallpaper_window());
上面的行允许我从get_wallpaper_window() 方法检索到的 HWND 在 SDL 中创建一个窗口。
由于涉及大量代码,我将链接my solution on github。这可以在您的桌面图标后面画出很多星星(尽管我相信它可以改进)。