有沒有什麼辦法可以在桌面背景上繪製WIN32並且在桌面背景重新繪製時也收到通知?繪製桌面背景(WIN32)
我嘗試這樣做:
desk = GetDesktopWindow();
dc = GetDC(desk);
MoveToEx(dc,0,0,NULL);
LineTo(dc,1680,1050);
ReleaseDC(desk,dc);
但它繪製在整個屏幕上,甚至超過那些在屏幕上的窗口。
有沒有什麼辦法可以在桌面背景上繪製WIN32並且在桌面背景重新繪製時也收到通知?繪製桌面背景(WIN32)
我嘗試這樣做:
desk = GetDesktopWindow();
dc = GetDC(desk);
MoveToEx(dc,0,0,NULL);
LineTo(dc,1680,1050);
ReleaseDC(desk,dc);
但它繪製在整個屏幕上,甚至超過那些在屏幕上的窗口。
您可以使用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;
}
下面是結果finddesktop.exe
Folder View: 000100A0
Desktop Window: 00010014
運行後,正如你所看到的窗口句柄有很大的不同。
只是引述MSDN:
的GetDesktopWindow函數返回 的句柄桌面窗口。 桌面窗口覆蓋整個 屏幕。桌面窗口是 的區域,在其上面繪製了其他窗口 。
所以你得到一個窗口上嵌套窗口。 我不是一個WIN32用戶,但我認爲這裏的方法已經到了較低的層次,掌握繪製背景圖片的圖形對象,並在那裏繪製。
我用desk = FindWindowEx(NULL,NULL,L「SysListView32」,NULL)更改第一行;但我認爲它與GetDesktopWindow獲得相同的窗口,因爲它具有相同的效果。 – Razvi 2009-07-24 09:20:26