unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
const
SET_LNG_CMD = WM_USER+2;
type
TForm1 =
class(TForm)
Button1: TButton;
Memo1: TMemo;
Memo2: TMemo;
Memo3: TMemo;
Button2: TButton;
procedure FormClick(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private-Deklarationen }
protected
procedure GetMessages(
var msg: Tmessage);
message SET_LNG_CMD;
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TForm1 }
function EnumWinx(hWnd: THandle; ProcID: PCardinal): Boolean;
stdcall;
var
WinProcId: cardinal;
Text: AnsiString;
begin
Result := True;
if IsWindowVisible(hWnd)
then
begin
GetWindowThreadProcessID(hWnd, WinProcId);
if ProcID^ = WinProcId
then
begin
SetLength(Text, SendMessage(hWnd, WM_GETTEXTLENGTH, 0, 0));
SendMessage(hWnd, WM_GETTEXT, Length(Text)+ 1, integer(Text));
//if Text = 'Unbenannt - Editor' then//Beispiel Text des gesuchten Fensters
//ShowWindow(hWnd, SW_MINIMIZE);//bei dir dann SW_HIDE
form1.memo2.lines.add(inttostr(hwnd));
form1.memo3.lines.add(text);
end;
end;
end;
procedure TForm1.GetMessages(
var msg: Tmessage);
begin
memo1.Lines.Add(inttostr(msg.Msg));
if msg.msg = SET_LNG_CMD
then
begin
ShowMessage('
hallo');
end;
end;
procedure TForm1.FormClick(Sender: TObject);
begin
// SendMessage( Self.Handle, SET_LNG_CMD, 0, 0 );
end;
procedure TForm1.Button1Click(Sender: TObject);
var i:integer;
begin
For i:=0
to memo2.lines.Count-1
do SendMessage(strtoint(memo2.lines.Strings[i]), SET_LNG_CMD, 0, 0 );
end;
procedure TForm1.FormActivate(Sender: TObject);
begin
memo1.Clear;
memo2.Clear;
memo3.Clear;
end;
procedure TForm1.Button2Click(Sender: TObject);
var i:integer;
ProcID: Cardinal;
WinProcId: Cardinal;
begin
memo1.Clear;
memo2.Clear;
GetWindowThreadProcessID(application.Handle, WinProcId);
EnumWindows(@EnumWinx, integer(@WinProcId));
end;
end.