program Project1;
{$APPTYPE CONSOLE}
uses
Windows;
type
TOpenOfficeWindow =
record
WindowHandle: THandle;
WindowTitle:
string;
end;
TOpenOfficeWindowArray =
array of TOpenOfficeWindow;
POpenOfficeWindowArray = ^TOpenOfficeWindowArray;
function EnumWindowsCallback(hwnd: THandle; WindowArray: POpenOfficeWindowArray)
: LongBool;
stdcall;
const
WINDOW_TITLE_BUFFER_SIZE = 65 * 1024;
OPENOFFICE_WINDOW_CLASSNAME = '
SALFRAME';
var
WindowTitle:
array [0 .. WINDOW_TITLE_BUFFER_SIZE]
of WideChar;
WindowClassName:
array [0 .. WINDOW_TITLE_BUFFER_SIZE]
of WideChar;
begin
Result := true;
// Uns interessieren nur sichtbare Fenster
if IsWindowVisible(hwnd)
then
begin
// Wir holen uns den ClassName des Fensters
FillChar(WindowClassName, SizeOf(WindowClassName), 0);
if (GetClassName(hwnd, @WindowClassName, WINDOW_TITLE_BUFFER_SIZE) > 0)
and (WindowClassName = OPENOFFICE_WINDOW_CLASSNAME)
then
begin
// Wir ermitteln den Fenster Titel
FillChar(WindowTitle, SizeOf(WindowTitle), 0);
GetWindowText(hwnd, @WindowTitle, WINDOW_TITLE_BUFFER_SIZE);
// Wir erweitern das übergebene WindowArray um 1 und füllen es mit den ermittelten Informationen
SetLength(WindowArray^, Length(WindowArray^) + 1);
WindowArray^[ High(WindowArray^)].WindowHandle := hwnd;
WindowArray^[ High(WindowArray^)].WindowTitle := WindowTitle;
end;
end;
end;
function EraseAndFillWindowArray(
var WindowArray: TOpenOfficeWindowArray)
: Boolean;
begin
// Array löschen
SetLength(WindowArray, 0);
// Wir lassen uns alle Fenster zurückgeben die auf dem Desktop angezeigt werden
EnumDesktopWindows(0, @EnumWindowsCallback, Cardinal(@WindowArray));
// Falls Einträge im WindowArray vorhanden sind, geben wir true, ansonsten false zurück
Result := Length(WindowArray) <> 0;
end;
var
WindowArray: TOpenOfficeWindowArray;
i : Integer;
begin
writeln(EraseAndFillWindowArray(WindowArray));
writeln;
for i := 0
to Length(WindowArray) - 1
do
begin
writeln('
Fenster Handle: ', WindowArray[i].WindowHandle);
writeln('
Fenster Titel: ', WindowArray[i].WindowTitle);
writeln;
end;
readln;
end.