Einzelnen Beitrag anzeigen

Benutzerbild von stoxx
stoxx

Registriert seit: 13. Aug 2003
1.111 Beiträge
 
#3

Re: Fenster suchen (Grösse bekannt!)

  Alt 11. Feb 2009, 17:06
Hab Dir mal meinen Code gesucht ...

den kann man auch so aufrufen

hWindow := FindWindowPartStr('Delphi-Praxis;Delphi-Forum', 'IEFrame');
Delphi-Quellcode:
function GetStringNr(const NR : integer; const Value : AnsiString; const delim : char = ';'): Ansistring;
var i, idx : integer;
    iOrd : byte;
    Res : AnsiString;
    Used : Integer;
begin
  Result := '';
  idx := 1;
  Used := 0;
  SetLength(Res, Length(Value));

  for i := 1 to length(Value) do
  begin
    if Value[i] = delim then
       begin
          inc(IDX);
          continue;
       end;
    If IDX > NR then break;
    if IDX = NR then
     begin
      inc(Used);
      Res[used] := Value[i];
     end;
  end; // von for
   SetLength(Res, Used);
   result := res;
end; // von GetStringNRh

//==============================================================================

type
  PFindWindowStruct = ^TFindWindowStruct;
  TFindWindowStruct = record
    CaptionPartCount : Integer;
    CaptionParts: string;
    ClassName: String;
    WindowHandle: THandle;
end;
//==============================================================================
function EnumWindowsProc(hWindow: hWnd; lParam: LongInt): boolean; stdcall;
var lpBuffer: PChar;
    WindowCaptionFound: boolean;
    ClassNameFound: boolean;
    i : Integer;
    s : String;
begin
  GetMem(lpBuffer, 255);
  result:=true;
  WindowCaptionFound:=false;
  ClassNameFound:=false;
  try
    if GetWindowText(hWindow, lpBuffer,255)>0 then begin

        WindowCaptionFound := true;
        for i := 1 to PFindWindowStruct(lParam).CaptionPartCount do begin
            s := GetStringNr(i,PFindWindowStruct(lParam).CaptionParts);
            if Pos(s, StrPas(lpBuffer) )= 0
               then WindowCaptionFound:= false;
        end; // for i (PFind)
    end;

    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 FindWindowPartStr(const aCaptionParts: string; const aWinClassName: string = ''): THandle;
var WindowInfo: TFindWindowStruct;
begin
  with WindowInfo do begin

        if aCaptionParts = 'then
          CaptionPartCount := 0 else
              CaptionPartCount := StrCharCount(aCaptionParts,';') + 1;

        CaptionParts := aCaptionParts;
        className := aWinClassName;
        WindowHandle := 0;
        EnumWindows(@EnumWindowsProc, LongInt(@WindowInfo));
        result := WindowHandle;
  end;
end;
Phantasie ist etwas, was sich manche Leute gar nicht vorstellen können.
  Mit Zitat antworten Zitat