Autor Beitrag
hans-maulwurf
Hält's aus hier
Beiträge: 10



BeitragVerfasst: Mi 26.10.05 21:13 
Hallöle,
also mit meinem Code bekomme ich Zugriff auf ein Editfeld. Problem ist nur, ich hab die classnames gecheckt und es gibt mehrere Felder die allesamt Edit heißen... Mit welcher Funktion kann ich nun die Handles auf diese Felder bekommen?

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
H := FindWindow(nil, Pchar('Fenstertitel'));
HChild := FindWindowEx(H, 0, PChar('Edit'), nil);

if HChild <> 0 then begin
...
end;


Danke :)
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mi 26.10.05 21:31 
FindWindowEx liefert dir doch schon das Handle!?!?? Ansonsten mit EnumChildWindows alle Edits suchen.
Blackheart666
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2195

XP
D3Prof, D6Pers.
BeitragVerfasst: Mi 26.10.05 22:03 
Hallo schätze mal das wird dir Helfen.
Hatte Ich mal von Torry !

ausblenden volle Höhe Delphi-Quelltext
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:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
{ Unit to demonstrate the usage of EnumWindows and some according API-functions
  Christoph Handel, Simon Reinhardt and Christian Kästner in October 1998

  Uses Messages to transport the Wnd-Handle.
  This way you do not need to directly use the Form variable }


unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Controls, Forms, StdCtrls,
  ComCtrls, ExtCtrls, TLHelp32, ShellApi;

type
  TMainForm = class(TForm)
    PanelTop: TPanel;
    btnEnumerate: TButton;
    PanelMain: TPanel;
    ListView: TListView;
    LblAnzahl: TLabel;
    procedure btnEnumerateClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure ListViewColumnClick(Sender: TObject; Column: TListColumn);
  private
    { Private-Deklarationen }
    WM_ENUMERATE_ID: integer;
  public
    { Public-Deklarationen }
    procedure WriteText(Wnd: HWnd);
    procedure WndProc(var Message: TMessage); override;
  end;

var
  MainForm   : TMainForm;
  SortColumn : integer;

function RegisterMessage: integer;
// get a messageID from Windows

function EnumWinProc(Wnd: HWnd; param: lParam): boolean; stdcall;
// this is the callbackfunction. Don't miss stdcall
// can't be part of the form.

implementation

{$R *.DFM}

function RegisterMessage: integer;
begin
  Result:= RegisterWindowMessage('Enumerate this Window');
end;

function EnumWinProc(Wnd: HWnd; param: lParam): boolean; stdcall;
var iMsgID: integer;
begin
  iMsgID:= RegisterMessage;
  SendMessage(param, iMsgID, 0, Wnd);
  // give data to main form
  Result:=true;
end;

procedure TMainForm.WndProc(var Message: TMessage);
begin
  if Message.Msg=WM_ENUMERATE_ID then
    // oh! Enumerate Window found a window, lets do something
    WriteText(Message.lParam)
  else
    inherited WndProc(Message);
end;

{This procedures by Simon Reinhardt:}
//Sort the listitems alphabetically
function MySortProc(Item1, Item2: TListItem; ParamSort: integer): integer; stdcall;
var T1,T2 : string;
begin
  case SortColumn of
    0 : begin
          T1:=Item1.Caption;
          T2:=Item2.Caption;
        end
    else begin
          T1:=Item1.SubItems[SortColumn-1];
          T2:=Item2.SubItems[SortColumn-1];
        end
  end;
  Result := lstrcmp(PChar(T1),PChar(T2));
end;

//fill in the listview with all the information
procedure TMainForm.WriteText(Wnd: HWnd);
var pcWinText       : PChar;
    NewItem         : TListItem;
    aProcessEntry32 : TProcessEntry32;
    aSnapshotHandle : THandle;
    WinVersion      : DWord;
    ProcessID       : longint;
    ContinueLoop    : boolean;
begin
  NewItem:=ListView.Items.Add;
  {Is Window Visible?}
  NewItem.Checked:=IsWindowVisible(wnd);
  {WindowCaption}
  pcWinText:= StrAlloc(102);
  GetWindowText(Wnd, pcWinText, 100);
  NewItem.Caption:=StrPas(pcWinText);
  StrDispose(pcWinText);
  {WindowClassName}
  pcWinText:= StrAlloc(102);
  GetClassName(Wnd, pcWinText, 100);
  NewItem.SubItems.Add(StrPas(pcWinText));
  StrDispose(pcWinText);
  {WindowHandle}
  NewItem.SubItems.Add(IntToHex(wnd, 8));
  {WindowThreadProcessID}
  GetWindowThreadProcessID(wnd,@ProcessID);
  NewItem.SubItems.Add(IntToHex(ProcessID, 8));
  {WindowsVersion}
  WinVersion:=GetProcessVersion(ProcessID);
  NewItem.SubItems.Add(IntToStr(WinVersion shr 16)+'.'+IntToStr(WinVersion mod $1000));
  {CommandLine}
  {According to Christian Kästner:}
  aSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
  aProcessEntry32.dwSize := Sizeof(aProcessEntry32);
  ContinueLoop := Process32First(aSnapshotHandle, aProcessEntry32);
  while integer(ContinueLoop) <> 0 do begin
    if aProcessEntry32.th32ProcessID = ProcessID then
      NewItem.SubItems.Add(ExtractFileName(aProcessEntry32.szExeFile));
    ContinueLoop := Process32Next(aSnapshotHandle,aProcessEntry32);
  end;
  CloseHandle(aSnapshotHandle);
  {end of Chrstian's stuff}
end;

//sort the listview on columnclick
procedure TMainForm.ListViewColumnClick(Sender: TObject;
  Column: TListColumn);
begin
  SortColumn:=Column.Index;
  ListView.CustomSort(@MySortProc, 0);
end;
{end of Simons part}

procedure TMainForm.btnEnumerateClick(Sender: TObject);
begin
  ListView.Items.Clear;
  EnumWindows(@EnumWinProc, self.Handle);
  // start EnumerateWindows, send the Handle of the Form
  // so function nows where to send the info
  LblAnzahl.Caption:='Anzahl : '+IntToStr(ListView.Items.Count);
end;

procedure TMainForm.FormCreate(Sender: TObject);
begin
  WM_ENUMERATE_ID:= RegisterMessage;
  // get our msgID
end;

end.
hans-maulwurf Threadstarter
Hält's aus hier
Beiträge: 10



BeitragVerfasst: Mi 26.10.05 22:06 
danke erstmal

aaalso, ich hab aus der Delphi Hilfe:

BOOL EnumChildWindows(
HWND hWndParent, // handle to parent window
WNDENUMPROC lpEnumFunc, // pointer to callback function
LPARAM lParam // application-defined value
);

parenthandle ist klar, callback function bedeutet doch bestimmt rekursiv aufrufen?

Ich hab jetzt vesucht, aus HChild ein dyn. Array zu machen -> Fehlermeldung: Inkompatible Typen LongBool und dynamic Array :D
ich hab keine Ahnung, was ich mit einem LongBool anfangen soll...
ausblenden Delphi-Quelltext
1:
2:
3:
var HChild: array of HWND;
...
HChild[i] := EnumChildWindows(H, @EnumChildProc, PChar('Edit'));


aber das funktioniert natürlich noch nicht... :)
hans-maulwurf Threadstarter
Hält's aus hier
Beiträge: 10



BeitragVerfasst: Mi 26.10.05 22:32 
sorry aber diese Unit hilft mir leider gar nicht.... also ich hab jetzt ne Weile rumprobiert und auch das Forum durchstöbert, aber ich blicks nicht ganz
toms
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1099
Erhaltene Danke: 2



BeitragVerfasst: Do 27.10.05 05:16 
user profile iconhans-maulwurf hat folgendes geschrieben:
Problem ist nur, ich hab die classnames gecheckt und es gibt mehrere Felder die allesamt Edit heißen... Mit welcher Funktion kann ich nun die Handles auf diese Felder bekommen?


Downloade dir mal meinen WinSpy (Im Forum zu finden)
Der erzeugt dir sogar den Findwindow-Code.
hans-maulwurf Threadstarter
Hält's aus hier
Beiträge: 10



BeitragVerfasst: Do 27.10.05 14:35 
naja das entsprechende Handle würde ich schon bekommen (hab X-Spy), aber ich will ja, dass mein Programm das von selbst macht.

Das handle ändert sich doch bei jedem Programmstart, oder?

Ich bräuchte jetzt nur einen Tipp, wie ich mit EnumChildWindows umgehe
Blackheart666
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2195

XP
D3Prof, D6Pers.
BeitragVerfasst: Do 27.10.05 14:57 
Genau das macht die Unit, sie zeigt Dir den Namen des Programms, den exe Namen, das Handle und der gleichen.
Ich hab mich noch nicht damit beschäftigt, aber Ich glaube Du beschreibst dein Problem zu ungenau oder besser gesagt sag mal einfach genau was Du vorhast.
Motzi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2931

XP Prof, Vista Business
D6, D2k5-D2k7 je Prof
BeitragVerfasst: Do 27.10.05 15:03 
Wenn du eine der letzten Versionen des X-Spy hast, kannst du dir von diesem auch Code zum Suchen des Fensters generieren lassen. Es besteht zwar noch das Problem, dass der FindWindow-Code möglicherweise nicht das korrekte Fenster findet, wenn es mehrere Fenster derselben Klasse gibt, aber in vielen Fällen ist es ohnehin besser/einfacher das Fenster über die Control-ID zu suchen. Du kannst frei wählen, wie das Fenster gesucht werden soll - über FindWindow(Ex) oder GetDlgItem (Control-ID).

Falls du es lieber selbst über EnumChildWindows machen willst, findest du im Forum bestimmt genug Beiträge zu diesem Thema Suche in der Entwickler-Ecke ENUMWINDOWS OR ENUMCHILDWINDOWS

Gruß, Motzi

_________________
gringo pussy cats - eef i see you i will pull your tail out by eets roots!
hans-maulwurf Threadstarter
Hält's aus hier
Beiträge: 10



BeitragVerfasst: Do 27.10.05 19:14 
na ich hab die 'last version running on windows 9x' oder so

Tut mir leid :)

im Forum such ja auch schon

Also ich will von meinem ICQ beispielsweise das obere Fenster auslesen.
Aber auch das untere ist von GetClassName RichEdit20a => Problem
und ich glaube das meinte Motzi ja auch gerade

ich weiß nicht was ich nehmen soll, FindWindow(Ex) oder GetDlgItem (Control-ID) oder EnumChildWindows. Sagt es mir^^

mir wurde am Anfang ja EnumChildWindows gesagt, aber ich bekomm die Funktion Syntaxmäßig nicht zum laufen...
toms
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1099
Erhaltene Danke: 2



BeitragVerfasst: Do 27.10.05 19:18 
Na dann sag ich's dir halt nochmals:

"Downloade dir mal meinen WinSpy (Im Forum zu finden)
Der erzeugt dir sogar den Findwindow-Code."

Oder den X-Spy.
hans-maulwurf Threadstarter
Hält's aus hier
Beiträge: 10



BeitragVerfasst: Do 27.10.05 19:22 
danke wiedermal
also mit

ausblenden Delphi-Quelltext
1:
 HChild := GetDlgItem(H, 0);					

bzw
ausblenden Delphi-Quelltext
1:
 HChild := GetDlgItem(H, 1);					

usw, bekomm ich jetz die Handles und kann auslesen.

wie bekomm ich nun raus, welches das obere der beiden 'RichEdit20a's ist?
toms
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1099
Erhaltene Danke: 2



BeitragVerfasst: Do 27.10.05 20:17 
Der WinSpy, X-Spy zeigen dir die Fenster Hierarchie an.
hans-maulwurf Threadstarter
Hält's aus hier
Beiträge: 10



BeitragVerfasst: Mo 07.11.05 17:05 
mit GetDlgItem bekomm ich handle aber nur wenn ich die nummer weiß (jaja, winspy is ja alles klar)

Aber ursprünglich wollte ich eigentlich von selbst die "Childs" finden

wie stelle ich das nun mit EnumChildWindows an? Oder brauch ich eine andere Funktion?!