Bạn có thể sử dụng Spy ++ để tìm cửa sổ nào là cửa sổ nền của máy tính để bàn.
Trên hệ thống của tôi, tôi thấy hệ thống phân cấp như sau:
- Window 000.100.098 "Chương trình quản lý" Progman
- Window 0001009E "" SHELLDLL_DefView
- Window 00100A0 "FolderView" SysListView32
Tôi đoán bạn đang đề cập đến SysListView32 - cửa sổ có tất cả các biểu tượng. Bạn có thể sử dụng FindWindowEx để tìm cửa sổ này.
Chỉnh sửa Bạn nên sử dụng kết hợp FindWindowEx và EnumerateChildWindows. Các mã được trình bày dưới đây có thể được biên dịch trong một hộp dòng lệnh như thế này: 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;
}
Đây là kết quả sau khi chạy finddesktop.exe
Folder View: 000100A0
Desktop Window: 00010014
Như bạn sẽ nhìn thấy cửa sổ xử lý khá khác nhau.
Nguồn
2009-07-24 09:09:10
Tôi thay đổi dòng đầu tiên bằng bàn = FindWindowEx (NULL, NULL, L "SysListView32", NULL); nhưng tôi nghĩ nó có cùng một cửa sổ với GetDesktopWindow vì nó có cùng tác dụng. – Razvi