Einzelnen Beitrag anzeigen

terence14
(Gast)

n/a Beiträge
 
#7

AW: Beim ersten Aufruf von GetWindowText -> Fehler 126

  Alt 1. Jan 2013, 09:40
hallo,
ich verwende auch die Funktion GetWindowText,
und zwar mit folgender Fehlerabfrage...

Delphi-Quellcode:


{-} function TPTest_SRDD._windowFound(myCaption: string): boolean;
    type PFindWindowStruct = ^TFindWindowStruct;
         TFindWindowStruct = record
                             fwsCaption,
                             fwsClassName : string;
                             fwsWindowHandle : THandle;
                             end; {record}
    {-}
    function _EnumWindowsProc(hWindow: hWnd; lParam: DWORD): boolean; stdcall
 
    var lpBuffer : PChar;
        boolWindowCaptionFound,
        boolClassNameFound : boolean;
    begin
    GetMem(lpBuffer, 255);
    FillChar(lpBuffer^, sizeof(lpBuffer^), #32);
    result:=True;
    boolWindowCaptionFound:=False;
    boolClassNameFound:=False;
    try if (GetWindowText(hWindow, lpBuffer, 255) > 0) then
               if (Pos(PFindWindowStruct(lParam).fwsCaption,
                       StrPas(lpBuffer)) = 1)
                  then boolWindowCaptionFound:=True;
            {-}
            if (PFindWindowStruct(lParam).fwsClassName = '') then begin
               boolClassNameFound:=True;
            end else begin
               if (GetClassName(hWindow, lpBuffer, 255) > 0) then
                  if (Pos(PFindWindowStruct(lParam).fwsClassName,
                          StrPas(lpBuffer)) > 0) then
                     boolClassNameFound:=True;
            end;
            {-}
            if (boolWindowCaptionFound and boolClassNameFound) then begin
               PFindWindowStruct(lParam).fwsWindowHandle:=hWindow;
               result:=False;
            end;
    finally FreeMem(lpBuffer, sizeof(lpBuffer^));
    end; {finally}
    end;
    {-}
    function _FindAWindow(myWinCaption, myWinClassName: string): THandle;
    var fws: TFindWindowStruct;
    begin
    result:=0;
    with fws do begin
         fwsCaption:=myWinCaption;
         fwsClassName:=myWinClassName;
         fwsWindowHandle:=0;
         if not(BOOL(EnumWindows(@_EnumWindowsProc, DWORD(@fws)))) then begin
            result:=fwsWindowHandle;
         end;
    end; {with}
    end;
    {-}
{-} begin
    //
    prvWindowHandle:=0;
    prvWindowHandle:=_FindAWindow(myCaption, ''); //'Formatieren', '');
    {-}
    result:=(prvWindowHandle > 0);
    {-}
{-} end;
dabei hat es nie einen Fehler gegeben
OS: WinVista 32bit
DV: Delphi2005

MfG,
terence
  Mit Zitat antworten Zitat