{** HandleListe aller Fenster}
function getWindowList: TList;
type
pList= ^TList;
function enumWindowsProc (hWnd: integer; bla: pointer): BOOL;
stdcall;
begin
pList(bla)^.Add( pointer( hWnd));
result:= true;
end;
begin
result:= TList.create;
Result.Capacity := 40;
enumWindows( @enumWindowsProc, integer(@result));
Result.Capacity := Result.count;
end;
{** Gibt die Caption eines Fensters zurück.}
function vGetWindowTextTimeOut(
const h:integer;
const timeOut: integer):
string;
var
dw: dword;
begin
setLength(result, 256);
sendMessageTimeOut(h, WM_GETTEXT, 256, integer(pchar(result)), SMTO_ABORTIFHUNG, timeOut, dw);
setLength(result, strlen( pchar( result)));
end;
{** Gibt den Klassennamen eines Fensters zurück.}
function vGetClassName(
const h:integer):
string;
begin
setLength(result, 100);
getClassName(h, pchar(result), 100);
setLength(result, strlen( pchar( result)));
end;
function vFindWindow(
const Klasse,
Name: pchar;
const usePos, mustBeVisible: Boolean): integer;
var
handle, wdh: integer;
WindowList: TList;
begin
result:= 0;
WindowList:= getWindowList;
if not usePos
then
begin
for wdh:= 0
to WindowList.count -1
do
begin
handle:= integer( WindowList[ wdh]);
if ((Klasse=NIL)
or (vgetClassName(
handle) = Klasse))
and ((Name=
NIL)
or (vGetWindowTextTimeOut(
handle, 250) =
Name))
then
begin
if not mustBeVisible
or isWindowVisible(
handle)
then
begin
result:=
handle;
break;
end;
end;
end;
end
else
begin
for wdh:= 0
to WindowList.count -1
do
begin
handle:= integer( WindowList[ wdh]);
if ((Klasse=NIL)
or (pos(Klasse, vgetClassName(
handle))>0))
and ((Name=NIL)
or (pos(
Name, vGetWindowTextTimeout(
handle, 250))>0))
then
begin
if not mustBeVisible
or isWindowVisible(
handle)
then
begin
result:=
handle;
break;
end;
end;
end;
end;
WindowList.free;
end;