diff --git a/Chameleon.lpi b/Chameleon.lpi index c797f83..e9cba0c 100644 --- a/Chameleon.lpi +++ b/Chameleon.lpi @@ -26,7 +26,7 @@ - + diff --git a/Chameleon.res b/Chameleon.res index c8f7da2..eaf6811 100644 Binary files a/Chameleon.res and b/Chameleon.res differ diff --git a/frmResults.pas b/frmResults.pas index 52c88bf..de2e104 100644 --- a/frmResults.pas +++ b/frmResults.pas @@ -16,8 +16,13 @@ type procedure TreeView1Change(Sender: TObject; Node: TTreeNode); procedure Savelistdata1Click(Sender: TObject); private + procedure GetWinInfoText(wnd: HWND; ParentNode: TTreeNode); + function GetWinInfoClassName(wnd: HWND; ParentNode: TTreeNode): String; procedure GetWinInfoStyle(wnd: HWND; ParentNode: TTreeNode); procedure GetWinInfoExtendedStyle(wnd: HWND; ParentNode: TTreeNode); + procedure GetWinInfoPlacement(wnd: HWND; ParentNode: TTreeNode); + procedure GetWinInfoListData(wnd: HWND; ParentNode: TTreeNode); + procedure GetWinInfoChildren(wnd: HWND; ParentNode: TTreeNode); public procedure GetWinInfo(wnd: HWND; ParentNode: TTreeNode); end; @@ -31,6 +36,18 @@ uses DfmEngine, StyleNames; {$R *.lfm} +function GetClassNameAsString(wnd: HWND): String; +var + class_name: array [0..100] of char; + len: Integer; +begin + len := GetClassName(wnd, class_name, 100); + if len > 0 then + Result := class_name + else + Result := ''; +end; + procedure TResults.TreeView1Change(Sender: TObject; Node: TTreeNode); begin if (Assigned(Node) and (Node.Text = '[List Data]')) then @@ -67,73 +84,44 @@ end; procedure TResults.GetWinInfo(wnd: HWND; ParentNode: TTreeNode); var - len, i, cbcount: integer; - Text: PChar; - class_name: array [0..100] of char; - R1, R2: TRect; - node1, node2: TTreeNode; - childlist: TList; - EnumParams: TEnumParams; - parentWnd: HWND; - itemtext: array [0..300] of char; + class_name: String; begin - if not IsWindow(wnd) then + if IsWindow(wnd) then begin + TreeView1.Items.AddChild(ParentNode, 'Handle = ' + IntToStr(wnd)); + GetWinInfoText(wnd, ParentNode); + class_name := GetWinInfoClassName(wnd, ParentNode); + TreeView1.Items.AddChild(ParentNode, 'Parent Handle = ' + IntToStr(GetParent(wnd))); + GetWinInfoStyle(wnd, ParentNode); + GetWinInfoExtendedStyle(wnd, ParentNode); + GetWinInfoPlacement(wnd, ParentNode); + { CompareText for case-insensitive comparison } + if CompareText(class_name, 'COMBOBOX') = 0 then + begin + GetWinInfoListData(wnd, ParentNode); + end; + GetWinInfoChildren(wnd, ParentNode); + end + else TreeView1.Items.AddChild(ParentNode, 'Handle = (INVALID HANDLE)'); - Exit; - end; - childlist := TList.Create; +end; + +procedure TResults.GetWinInfoText(wnd: HWND; ParentNode: TTreeNode); +var + len: integer; + Text: PChar; +begin len := GetWindowTextLength(wnd) + 1; GetMem(Text, len); GetWindowText(wnd, Text, len); - GetWindowRect(wnd, R1); - Windows.GetClientRect(wnd, R2); - GetClassName(wnd, class_name, 100); - parentWnd := GetParent(wnd); - EnumParams.List := childlist; - EnumParams.ParentWnd := wnd; - EnumChildWindows(wnd, @EnumChildrenProc, integer(@EnumParams)); - - with TreeView1.Items do - begin - AddChild(ParentNode, 'Handle = ' + IntToStr(wnd)); - AddChild(ParentNode, 'Caption = ' + Text); - AddChild(ParentNode, 'Class name = ' + class_name); - AddChild(ParentNode, 'Parent Handle = ' + IntToStr(parentWnd)); - GetWinInfoStyle(wnd, ParentNode); - GetWinInfoExtendedStyle(wnd, ParentNode); - node1 := AddChild(ParentNode, 'Placement'); - AddChild(node1, 'Left = ' + IntToStr(R1.Left)); - AddChild(node1, 'Top = ' + IntToStr(R1.Top)); - AddChild(node1, 'Width = ' + IntToStr(R1.Right - R1.Left)); - AddChild(node1, 'Height = ' + IntToStr(R1.Bottom - R1.Top)); - AddChild(node1, 'ClientWidth = ' + IntToStr(R2.Right)); - AddChild(node1, 'ClientHeight = ' + IntToStr(R2.Bottom)); - if (CompareText(class_name, 'COMBOBOX') = 0) then - begin - node1 := AddChild(ParentNode, '[List Data]'); - cbcount := SendMessage(wnd, CB_GETCOUNT, 0, 0); - for i := 1 to cbcount do - begin - SendMessage(wnd, CB_GETLBTEXT, i - 1, longint(@itemtext)); - node2 := AddChild(node1, 'Item #' + IntToStr(i)); - AddChild(node2, 'Text = ' + itemtext); - AddChild(node2, 'Data = ' + - IntToStr(SendMessage(wnd, CB_GETITEMDATA, i - 1, 0))); - end; - end; - if childlist.Count > 0 then - begin - node1 := AddChild(ParentNode, 'Children information'); - for i := 1 to childlist.Count do - begin - node2 := AddChild(node1, 'Child #' + IntToStr(i)); - GetWinInfo(integer(childlist[i - 1]), node2); - end; - end; - end; + TreeView1.Items.AddChild(ParentNode, 'Caption = ' + Text); FreeMem(Text); - childlist.Free; +end; + +function TResults.GetWinInfoClassName(wnd: HWND; ParentNode: TTreeNode): String; +begin + Result := GetClassNameAsString(wnd); + TreeView1.Items.AddChild(ParentNode, 'Class name = ' + Result); end; procedure TResults.GetWinInfoStyle(wnd: HWND; ParentNode: TTreeNode); @@ -180,4 +168,73 @@ begin list.Free(); end; +procedure TResults.GetWinInfoPlacement(wnd: HWND; ParentNode: TTreeNode); +var + R1, R2: TRect; + node1: TTreeNode; +begin + GetWindowRect(wnd, R1); + Windows.GetClientRect(wnd, R2); + with TreeView1.Items do + begin + node1 := AddChild(ParentNode, 'Placement'); + AddChild(node1, 'Left = ' + IntToStr(R1.Left)); + AddChild(node1, 'Top = ' + IntToStr(R1.Top)); + AddChild(node1, 'Width = ' + IntToStr(R1.Right - R1.Left)); + AddChild(node1, 'Height = ' + IntToStr(R1.Bottom - R1.Top)); + AddChild(node1, 'ClientWidth = ' + IntToStr(R2.Right)); + AddChild(node1, 'ClientHeight = ' + IntToStr(R2.Bottom)); + end; +end; + +procedure TResults.GetWinInfoListData(wnd: HWND; ParentNode: TTreeNode); +var + i, cbcount: integer; + node1, node2: TTreeNode; + itemtext: array [0..300] of char; +begin + with TreeView1.Items do + begin + node1 := AddChild(ParentNode, '[List Data]'); + cbcount := SendMessage(wnd, CB_GETCOUNT, 0, 0); + for i := 1 to cbcount do + begin + SendMessage(wnd, CB_GETLBTEXT, i - 1, longint(@itemtext)); + node2 := AddChild(node1, 'Item #' + IntToStr(i)); + AddChild(node2, 'Text = ' + itemtext); + AddChild(node2, 'Data = ' + + IntToStr(SendMessage(wnd, CB_GETITEMDATA, i - 1, 0))); + end; + end; +end; + +procedure TResults.GetWinInfoChildren(wnd: HWND; ParentNode: TTreeNode); +var + i: integer; + node1, node2: TTreeNode; + childlist: TList; + EnumParams: TEnumParams; + class_name: String; +begin + childlist := TList.Create; + + EnumParams.List := childlist; + EnumParams.ParentWnd := wnd; + EnumChildWindows(wnd, @EnumChildrenProc, integer(@EnumParams)); + + with TreeView1.Items do + begin + if childlist.Count > 0 then + begin + node1 := AddChild(ParentNode, 'Children information'); + for i := 1 to childlist.Count do + begin + node2 := AddChild(node1, 'Child #' + IntToStr(i)); + GetWinInfo(integer(childlist[i - 1]), node2); + end; + end; + end; + childlist.Free; +end; + end.