Einzelnen Beitrag anzeigen

Monsta3

Registriert seit: 11. Dez 2004
16 Beiträge
 
#9

Re: Fenster mit bestimmten Titel automatisch schließen

  Alt 22. Jan 2005, 15:25
Hab ich bei SwissDelphiCenter gefunden. Ist von Thomas Stutz.

Delphi-Quellcode:
{
  FindWindowByTitle returns the handle of a window that
  contains a certain "WindowTitle".

  FindWindowByTitle gibt das Handle jenes Fensters zurück,
  das im Titel den String "WindowTitle" enthält.
}


function FindWindowByTitle(WindowTitle: string): Hwnd;
var
  NextHandle: Hwnd;
  NextTitle: array[0..260] of char;
begin
  // Get the first window
  NextHandle := GetWindow(Application.Handle, GW_HWNDFIRST);
  while NextHandle > 0 do
  begin
    // retrieve its text
    GetWindowText(NextHandle, NextTitle, 255);
    if Pos(WindowTitle, StrPas(NextTitle)) <> 0 then
    begin
      Result := NextHandle;
      Exit;
    end
    else
      // Get the next window
      NextHandle := GetWindow(NextHandle, GW_HWNDNEXT);
  end;
  Result := 0;
end;

{
  Example how to search for a window that contains the
  word "notepad" and maximize it.

  Beispiel, wie man ein Fenster "notepad" findet
  und es anschliessend maximiert.
}


procedure TForm1.Button1Click(Sender: TObject);
var
  h: hwnd;
begin
  h := FindWindowByTitle('notepad');
  if h <> 0 then // if we found notepad
    ShowWindow(h, SW_MAXIMIZE)
  else
    ShowMessage('not found.');
end;
http://www.swissdelphicenter.ch/de/showcode.php?id=327
  Mit Zitat antworten Zitat