Delphi-PRAXiS
Seite 2 von 2     12   

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Programmieren allgemein (https://www.delphipraxis.net/40-programmieren-allgemein/)
-   -   Overload bei Funktion, beide Parameter sind Ganzzahl (https://www.delphipraxis.net/52734-overload-bei-funktion-beide-parameter-sind-ganzzahl.html)

mika 2. Sep 2005 14:24

Re: Overload bei Funktion, beide Parameter sind Ganzzahl
 
BugSuchWochenenden sind doch die besten Wochenenden :)

Ne mal im Ernst: Meint Ihr wirklich besser 2 Methoden? Ich wollt das eigentlich nur machen weil
ich Overload so selten benutze und dachte das ist mal ne Stelle wo das gut wäre :)

Mir auch egal dann mach ich 2 Funktionen (ich benutzt die zwar nur ehh selber aber will das trotzdem
sauber haben)


Ps.: Der Fehler mit der Exception tritt nur auf wenn ich AddProgram aus der CallbackRoutine aufrufe,
ich probier das mal anders zu machen und guck obs dann geht.

mika 2. Sep 2005 14:38

Re: Overload bei Funktion, beide Parameter sind Ganzzahl
 
So wenn man die Funktion ReadToplevelPrograms so umbaut:

Delphi-Quellcode:
Function TRunningPrograms.ReadToplevelPrograms: Boolean;
Type
  PMyEnumParam = ^TMyEnumParam;
  TMyEnumParam = Record
    Handles: TStringlist;
    Captions: TStringlist;
  End;

Var
  ndx: Integer;
  Handlelist,
  Captionlist: TStringlist;
  Params: TMyEnumParam;

  function GetWindows(const hWnd : THandle; Param: PMyEnumParam): LongBool; stdcall;
  var
    cLen: Longint;
    strCaption: String;

  begin
    Result := True;
    if (IsWindowVisible(hWnd)) and
       ((GetWindowLong(hWnd, GWL_HWndPARENT) = 0) or
       (GetWindowLong(hWnd, GWL_HWndPARENT) = GetDesktopWindow)) and
       (GetWindowLong(hWnd, GWL_EXSTYLE) and WS_EX_TOOLWINDOW = 0) then
    begin
      cLen := SendMessage(hWnd, WM_GETTEXTLENGTH, 0, 0);
      if cLen > 0 then
      begin
        SetLength(strCaption, cLen);
        SendMessage(hWnd, WM_GETTEXT, cLen + 1, Longint(Pchar(strCaption)));
        Param.Handles.Add(IntToStr(hWnd));
        Param.Captions.Add(strCaption);
      end;
    end;
    // mit Result = False kann die Callbackfunktion vorzeitig verlassen werden
  end;

Begin
  If Assigned(oPrograms) then
  begin
    Params.Handles := TStringList.Create;
    Params.Captions := TStringList.Create;

    EnumWindows(@GetWindows, LPARAM(@Params));
    for ndx := 0 to Params.Handles.Count - 1 do
    begin
      AddProgram(StrToInt(Params.Handles.Strings[ndx]), Params.Captions.Strings[ndx]);
    end;

    Params.Handles.Free;
    Params.Captions.Free;
    Result := True;
  end else
    Result := False;
End;
Dann funktioniert das auch mit dem AddProgram. Danke an alle die mir Antworten gegeben haben, ich programmier jetzt mal weiter.

Cu! :hi:


Alle Zeitangaben in WEZ +1. Es ist jetzt 18:54 Uhr.
Seite 2 von 2     12   

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz