有没有办法在WIN32中绘制桌面背景,并在重新绘制桌面背景时接收通知?
我试过这个:
desk = GetDesktopWindow();
dc = GetDC(desk);
MoveToEx(dc,0,0,NULL);
LineTo(dc,1680,1050);
ReleaseDC(desk,dc);
Run Code Online (Sandbox Code Playgroud)
但它在整个屏幕上绘制,甚至在屏幕上的窗口上.
您可以使用Spy ++查找哪个窗口是桌面背景窗口.
在我的系统上,我看到以下层次结构:
我猜你指的是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;
}
Run Code Online (Sandbox Code Playgroud)
以下是运行finddesktop.exe后的结果
Folder View: 000100A0
Desktop Window: 00010014
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,窗口把手是完全不同的.
| 归档时间: |
|
| 查看次数: |
6495 次 |
| 最近记录: |