AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Win32/Win64 API (native code) Delphi EnumWindowsProc -> EAccessError, OutOfResources
Thema durchsuchen
Ansicht
Themen-Optionen

EnumWindowsProc -> EAccessError, OutOfResources

Ein Thema von Jonas · begonnen am 24. Jul 2006 · letzter Beitrag vom 9. Aug 2006
Antwort Antwort
Muetze1
(Gast)

n/a Beiträge
 
#1

Re: EnumWindowsProc -> EAccessError, OutOfResources

  Alt 29. Jul 2006, 17:46
Ok, ich habe mich geirrt in 2 Dingen:

1. Die EnumWindowProc darf doch lokal sein!
2. EnumWindows() ist bei D5 u.a. noch so definiert, dass die EnumWindowProc als Pointer definiert wurde und nicht als Procedure Prototype.

Hier ein funktionierender Code:
Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    ListBox1: TListBox;
    procedure FormShow(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

type
  TFensterInfo = record
    Handle: HWND;
    Caption: String;
    Icon: HIcon;
  end;
  PFensterInfoList = ^TFensterInfoList;
  TFensterInfoList = Array Of TFensterInfo;

Var
  WindowList: TFensterInfoList;

Function EnumWindowsProc(Wnd: HWND; lp: LPARAM): LongBool; stdcall;
Const
  coBufferSize = 2048;
Var
  lList: PFensterInfoList;
  lCaption: String;
  lCapLen: Integer;
Begin
  Result := True;
  lList := PFensterInfoList(lp);

  If IsWindowVisible(Wnd) and
     ((GetWindowLong(Wnd, GWL_HWNDPARENT)=0) or
      (HWND(GetWindowLong(Wnd, GWL_HWNDPARENT))=GetDesktopWindow)) and
     ((GetWindowLong(Wnd, GWL_EXSTYLE) and WS_EX_TOOLWINDOW)=0) then
  begin
    SetLength(lCaption, coBufferSize);
    lCapLen := SendMessage(Wnd, WM_GETTEXT, coBufferSize, Integer(PChar(lCaption)));
    SetLength(lCaption, lCapLen);

    SetLength(lList^, Length(lList^)+1);
    lList^[High(lList^)].Caption := lCaption;
    lList^[High(lList^)].Handle := Wnd;
  end;
end;

procedure Tasks();
Begin
  SetLength(WindowList, 0);

  EnumWindows(@EnumWindowsProc, Integer(@WindowList));
End;

procedure TForm1.FormShow(Sender: TObject);
Var
  i: Integer;
begin
  Tasks;

  For i := Low(WindowList) To High(WindowList) Do
    ListBox1.Items.Add(WindowList[i].Caption);
end;

end.
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 16:33 Uhr.
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