Board index » delphi » EnumWindows proc - where am I going wrong?

EnumWindows proc - where am I going wrong?

Quote
m....@nospam.irl.cri.nz (Mike Fee) wrote:
>function EnumWindowsProcedure(TheHWind : Thandle; TheLParam : lParam) :

Maybe you should add the stdcall directive.

Smola
Slowly going deaf.

 

Re:EnumWindows proc - where am I going wrong?


Quote
Mike Fee <m....@nospam.irl.cri.nz> wrote in message

news:MPG.135bc2b0c811c09998968d@newshost.comnet.co.nz...

Quote
> Hi all,

> I am trying to produce a component that lists all running windows (a bit
> like the 'Close Program' window that appears after a 3-fingered salute on
> Win98. I am using EnumWindows but it doesn't appear to operate as my
> reading of the Win32 help files describe. >

  The button code outputs around 150 lines to the Memo (via the

Quote
> EnumWindowsProcedure) but all of them have the same argument in TheHWind.
> I expected a few less calls, and all with different handles.
> What am I doing wrong?

Mike, try the following example.  It's a little easier to understand.
Tested with D5.    Regards Bill

implementation

function EnumWindowsProc(Wnd: HWND; AMemo: TMemo): Bool; stdcall;
begin
  Result := True;
  AMemo.Lines.Add(Format('%d', [Wnd]));
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Memo1.Lines.Clear;
  EnumWindows(@EnumWindowsProc, Integer(Memo1));
  Memo1.Lines.Add('Completed');
end;

Re:EnumWindows proc - where am I going wrong?


Hi all,

I am trying to produce a component that lists all running windows (a bit
like the 'Close Program' window that appears after a 3-fingered salute on
Win98. I am using EnumWindows but it doesn't appear to operate as my
reading of the Win32 help files describe. The following code is a
simplification of what I was trying, and illustrates the problem:

function EnumWindowsProcedure(TheHWind : Thandle; TheLParam : lParam) :
boolean;
begin
  Form1.memo1.lines.add(inttostr(integer(TheHWind)));
  result := TRUE;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  TheEnumWindowsProcPointer : pointer;
begin
  Memo1.Clear;
  TheEnumWindowsProcPointer := @EnumWindowsProcedure;
  if EnumWindows(TheEnumWindowsProcPointer,0) then
Memo1.lines.add('completed');
end;

The button code outputs around 150 lines to the Memo (via the
EnumWindowsProcedure) but all of them have the same argument in TheHWind.
I expected a few less calls, and all with different handles.
What am I doing wrong?

Mike.

Re:EnumWindows proc - where am I going wrong?


In article <8cr6a4$l8...@bob.news.rcn.net>, bi...@catoctinsoftware.com
says...

Quote
> Mike, try the following example.  It's a little easier to understand.
> Tested with D5.    Regards Bill

Thanks - when I added 'stdcall', my original program worked.

Other Threads