unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
PFindWindowStruct = ^TFindWindowStruct;
TFindWindowStruct =
record
Caption:
string;
ClassName:
String;
WindowHandle: THandle;
end;
type
TForm1 =
class(TForm)
ListBox1: TListBox;
Image1: TImage;
Button1: TButton;
PaintBox1: TPaintBox;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
//sammeln aller infos und schreiben dieser in eine listbox - nur so, zum testen
function EnumWinProc(Wnd: THandle; LParam: LongInt): Boolean;
stdcall;
var
WinCaption :
string;
Len: integer;
begin
Result := True;
Len := GetWindowTextLength(Wnd);
SetLength(WinCaption, Len);
GetWindowText(Wnd, PChar(WinCaption), Len+1);
if Trim(WinCaption) <> '
'
then
Form1.Listbox1.Items.Add(Format('
%.6x : %s', [Wnd, WinCaption]));
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
EnumWindows(@EnumWinProc, 0);
end;
function EnumWindowsProc(hWindow: hWnd; lParam: LongInt): boolean;
stdcall;
var lpBuffer: PChar;
WindowCaptionFound: boolean;
ClassNameFound: boolean;
begin
GetMem(lpBuffer, 255);
result:=true;
WindowCaptionFound:=false;
ClassNameFound:=false;
try
if GetWindowText(hWindow, lpBuffer,255)>0
then
if Pos(PFindWindowStruct(lParam).Caption, StrPas(lpBuffer))>0
then WindowCaptionFound:=true;
if PFindWindowStruct(lParam).ClassName='
'
then
ClassNameFound:=true
else if GetClassName(hWindow, lpBuffer, 255)>0
then
if Pos(PFindWindowStruct(lParam).ClassName, StrPas(lpBuffer))>0
then ClassNameFound:=true;
if (WindowCaptionFound
and ClassNameFound)
then begin
PFindWindowStruct(lParam).WindowHandle:=hWindow;
result:=false;
end;
finally
FreeMem(lpBuffer, sizeof(lpBuffer^));
end;
end;
function FindAWindow(WinCaption:
string; WinClassName:
string): THandle;
var WindowInfo: TFindWindowStruct;
begin
with WindowInfo
do begin
caption := WinCaption;
className := WinClassName;
WindowHandle := 0;
EnumWindows(@EnumWindowsProc, LongInt(@WindowInfo));
result := WindowHandle;
end;
end;
//hier wird das fenster gesucht und das handle zugewiesen
procedure TForm1.Button1Click(Sender: TObject);
var TheWindowHandle: THandle;
begin
TheWindowHandle:=FindAWindow('
Renderer', '
');
if TheWindowHandle=0
then
ShowMessage('
Window not found!')
else
PaintBox1.Canvas.Handle := (TheWindowHandle);
PaintBox1.Repaint;
//ShowWindow(TheWindowHandle, SW_SHOWMINNOACTIVE);
//hier wird das fenster in den vordergrund geholt
//allerdings samt des hauptfenstrers der anderen applikation
//BringWindowToTop(TheWindowHandle); end;
end.