Vous pouvez utiliser Spy ++ pour trouver quelle fenêtre est la fenêtre d'arrière-plan du bureau.
Sur mon système, je vois la hiérarchie suivante:
- fenêtre 000100098 "Gestionnaire de programme" Progman
- Fenêtre 0001009E "" SHELLDLL_DefView
- fenêtre 00100A0 "FolderView" SysListView32
Je suppose que vous faites référence à SysListView32 - la fenêtre avec toutes les icônes. Vous pouvez utiliser FindWindowEx pour trouver cette fenêtre.
Édition Vous devez utiliser une combinaison de FindWindowEx et EnumerateChildWindows. Le code présenté ci-dessous peut être compilé dans une boîte de ligne de commande comme ceci: 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;
}
Voici les résultats après l'exécution finddesktop.exe
Folder View: 000100A0
Desktop Window: 00010014
Comme vous pouvez voir les poignées de fenêtre sont tout à fait différentes.
Je change la première ligne avec desk = FindWindowEx (NULL, NULL, L "SysListView32", NULL); mais je pense qu'il obtient la même fenêtre que GetDesktopWindow car il a le même effet. – Razvi