1 pièce(s) jointe(s)
Win32 : GetAncestor() et IsChild()
Bonjour tout le monde,
je cherche à récupérer deux handles de fenêtres windows et à faire en sorte que l'une d'entre elle soit enfant de l'autre. Cependant, je rencontre quelques problèmes de compréhension sur ce test. Voici mon code :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| #include <iostream>
#include <Windows.h>
using namespace std;
int main()
{
static LPCTSTR szWindowClass = TEXT("CalcFrame");
HWND calc = FindWindow(szWindowClass, NULL);
static LPCTSTR szWindowClass2 = TEXT("Notepad");
HWND notepad = FindWindow(szWindowClass2, NULL);
static LPCTSTR szWindowClass3 = TEXT("Desktop");
HWND desk = FindWindow(szWindowClass3, NULL);
cout << "desk : " << desk << endl;
cout << "calc : " << calc << endl;
cout << "notepad : " << notepad << endl;
cout << "parent calc : " << GetParent(calc) << endl;
cout << "GetWindow(calc, GW_OWNER) : " << GetWindow(calc, GW_OWNER) << endl;
cout << "GetAncestor(calc, GA_PARENT) : " << GetAncestor(calc, GA_PARENT) << endl;
cout << "parent notepad : " << GetParent(notepad) << endl;
cout << "GetWindow(notepad, GW_OWNER) : " << GetWindow(notepad, GW_OWNER) << endl;
cout << "GetAncestor(notepad, GA_PARENT) : " << GetAncestor(notepad, GA_PARENT) << endl;
cout << "------------" << endl;
HWND res = SetParent(notepad, calc);
cout << "res (SetParent(notepad, calc) : " << res << endl;
cout << "parent notepad : " << GetParent(notepad) << endl;
cout << "GetWindow(notepad, GW_OWNER) : " << GetWindow(notepad, GW_OWNER) << endl;
cout << "GetAncestor(notepad, GA_PARENT) : " << GetAncestor(notepad, GA_PARENT) << endl;
cout << "IsChild(calc, notepad) : " << IsChild(calc, notepad) << endl;
cout << "------------" << endl;
HWND newRes = SetParent(notepad, desk);
cout << "newRes (SetParent(notepad, desk) : " << newRes << endl;
cout << "GetAncestor(notepad, GA_PARENT) : " << GetAncestor(notepad, GA_PARENT) << endl;
return 0;
} |
Je me rends compte alors de plusieurs choses :
- le handle de mon Desktop n'est pas retrouvé au départ.
- GetParent et GetWindow(*, GW_OWNER) me retournent 0x0 contrairement à GetAncestor qui retourne le bon handle du parent avant et après un SetParent().
- Même si GetAncestor renvoit un handle correct, un IsChild() de l'enfant juste après me retourne 0x0.. La méthode serait liée au owner plus qu'au parent ?
- Enfin, on pourrait imaginer que certaines fenêtres windows ne peuvent s'utiliser comme conteneur d'autres fenêtres comme la calculette ... (je n'y crois pas trop mais c'est une hypothèse). Qu'en pensez-vous ?
Auriez-vous des idées ? Je pense que j'ai un problème de compréhension.
Merci beaucoup :)