unit windowmanager;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids, ValEdit;
type
Tmanager =
class(TForm)
ValueListEditor1: TValueListEditor;
Label1: TLabel;
Label2: TLabel;
Button1: TButton;
Button2: TButton;
procedure FormShow(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
manager: Tmanager;
implementation
uses Unit1;
{$R *.dfm}
function GetText(Wnd: HWND):
string;
//holt Fenster-Titel
var
textlength: Integer;
Text: PChar;
begin
textlength := SendMessage(Wnd, WM_GETTEXTLENGTH, 0, 0);
if textlength = 0
then Result := '
'
else
begin
GetMem(Text, textlength + 1);
SendMessage(Wnd, WM_GETTEXT, textlength + 1, Integer(Text));
Result := Text;
FreeMem(Text);
end;
end;
function EnumWindowsProc(Wnd: HWND; lParam: lParam): BOOL;
stdcall;
//listet sichtbare Fenster, die in der Taskleiste sind, auf
begin
Result := True;
if (IsWindowVisible(Wnd)
or IsIconic(wnd))
and
((GetWindowLong(Wnd, GWL_HWNDPARENT) = 0)
or
(GetWindowLong(Wnd, GWL_HWNDPARENT) = GetDesktopWindow))
and
(GetWindowLong(Wnd, GWL_EXSTYLE)
and WS_EX_TOOLWINDOW = 0)
and (IntToStr(Wnd) <> '
' )
then
begin
//hier hakt es dann, weiß aber nicht wo genau der Fehler ist.
manager.ValueListEditor1.InsertRow(IntToStr(Wnd), GetText(Wnd), true);
end;
end;
procedure Tmanager.FormShow(Sender: TObject);
var
Param: Longint;
i : Integer;
begin
ValueListEditor1.Strings.Clear;
EnumWindows(@EnumWindowsProc, Param);
ShowMessage(IntToStr(ValueListEditor1.RowCount));
{Fenster aus array hinzufügen}
for i:=0
to High(fenster)
do
begin
manager.ValueListEditor1.InsertRow(fenster[i, 0]+'
*', GetText(StrToInt(fenster[i, 0])), true);
end;
end;
procedure Tmanager.Button1Click(Sender: TObject);
//Fenster-verstecken Button
var
pos1 : Integer;
title :
String;
begin
pos1 := POS('
*', ValueListEditor1.Keys[ValueListEditor1.Row]);
if (pos1 <=0)
then
begin
//vestecken...
SetLength(fenster,High(fenster)+2);
SetLength(fenster[High(fenster)],2);
title := GetText(StrToInt(ValueListEditor1.Keys[ValueListEditor1.Row]));
if (Length(title) >= 30)
then
title := Copy(title, 0, 28)+'
...';
fenster[High(fenster),1] := title;
fenster[High(fenster),0] := ValueListEditor1.Keys[ValueListEditor1.Row];
ShowWindow(StrToInt(fenster[High(fenster), 0]), SW_HIDE);
{aktualiesieren...}
ValueListEditor1.Keys[ValueListEditor1.Row] := ValueListEditor1.Keys[ValueListEditor1.Row]+'
*';
end
else
MessageDlg('
Fenster schon verborgen.', mtWarning, [mbok], 0);
end;
procedure Tmanager.Button2Click(Sender: TObject);
//Fenster-Anzeigen Button
var
pos1, int, i : Integer;
title :
String;
begin
pos1 := POS('
*', ValueListEditor1.Keys[ValueListEditor1.Row]);
if (pos1 >=0)
then
begin
title := ValueListEditor1.Values[ValueListEditor1.Keys[ValueListEditor1.Row]];
if (Length(title) >= 30)
then
title := Copy(title, 0, 28)+'
...';
{nach String im Array suchen:}
for i:=0
to High(fenster)
do
begin
if (fenster[i, 1] = title)
then
int := i;
end;
ShowWindow(StrToInt(fenster[int, 0]), SW_SHOW);
Form1.delete_row(int);
{Manager-Fenster in den Vordergrund bringen}
SetForegroundWindow(
Handle);
{aktualiesieren...}
pos1 := POS('
*', ValueListEditor1.Keys[ValueListEditor1.Row]);
if (pos1 >=0)
then
begin
ValueListEditor1.Keys[ValueListEditor1.Row] := COPY(ValueListEditor1.Keys[ValueListEditor1.Row], 1, pos1-1);
end;
end
else
MessageDlg('
Fenster wurde nicht versteckt.', mtWarning, [mbok], 0);
end;
end.