Also ich habe das jetzt so gemacht:
Code:
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;
procedure TForm1.Button1Click(Sender: TObject);
var TheWindowHandle: THandle;
begin
TheWindowHandle:=FindAWindow('SpeedCommander 11', '');
if TheWindowHandle=0 then
ShowMessage('Window not found!')
else
PostMessage(TheWindowHandle, wm_KeyDown, VK_F1,0);
end;
Die Hilfe vom SpeedCommander Wird aufgerufen, sobald ich auf den Button klicke, das heißt der SpeedCommander kann auch minimiert sein. Sollte auch mit anderen Programmen funktionieren!