gpt4 book ai didi

c++ - 在桌面背景上绘图(WIN32)

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:20:26 26 4
gpt4 key购买 nike

有什么方法可以在WIN32的桌面背景上绘制,并且在桌面背景重绘时也能收到通知?

我试过这个:

desk = GetDesktopWindow();
dc = GetDC(desk);
MoveToEx(dc,0,0,NULL);
LineTo(dc,1680,1050);
ReleaseDC(desk,dc);

但它绘制在整个屏幕上,甚至在屏幕上的窗口上。

最佳答案

您可以使用 Spy++ 查找哪个窗口是桌面背景窗口。

在我的系统上,我看到以下层次结构:

  • 窗口 000100098“程序管理器”Progman
    • 窗口 0001009E ""SHELLDLL_DefView
      • 窗口 00100A0“FolderView”SysListView32

我猜您指的是 SysListView32 - 带有所有图标的窗口。您可以使用 FindWindowEx找到这个窗口。

编辑您应该结合使用 FindWindowEx 和 EnumerateChildWindows。下面显示的代码可以像这样在命令行框中编译:cl/EHsc finddesktop.cpp/DUNICODE/link user32.lib

#include <windows.h>
#include <iostream>
#include <string>

BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM lParam)
{
std::wstring windowClass;
windowClass.resize(255);

unsigned int chars = ::RealGetWindowClass(hwnd, &*windowClass.begin(), windowClass.size());
windowClass.resize(chars);

if (windowClass == L"SysListView32")
{
HWND* folderView = reinterpret_cast<HWND*>(lParam);
*folderView = hwnd;

return FALSE;
}

return TRUE;
}

int wmain()
{
HWND parentFolderView = ::FindWindowEx(0, 0, L"Progman", L"Program Manager");
if (parentFolderView == 0)
{
std::wcout << L"Couldn't find Progman window, error: 0x" << std::hex << GetLastError() << std::endl;
}

HWND folderView = 0;
::EnumChildWindows(parentFolderView, EnumChildProc, reinterpret_cast<LPARAM>(&folderView));

if (folderView == 0)
{
std::wcout << L"Couldn't find FolderView window, error: 0x" << std::hex << GetLastError() << std::endl;
}
HWND desktopWindow = ::GetDesktopWindow();

std::wcout << L"Folder View: " << folderView << std::endl;
std::wcout << L"Desktop Window: " << desktopWindow << std::endl;

return 0;
}

这是运行finddesktop.exe后的结果

Folder View: 000100A0
Desktop Window: 00010014

如您所见,窗口句柄完全不同。

关于c++ - 在桌面背景上绘图(WIN32),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1176448/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com