PDA

View Full Version : problem with EnumWindows(); API



Blah
13-08-2004, 01:54 AM
I had been having problems with an old app of mine it wouldnt load or show anything and ive just recently picked it up to see why all of a sudden it stopped working.

After alot of messing around it came down to EnumWindows() freezing the app which i also used on startup tht's why it froze without showing anything.

This is my function......


Function WindowList(wHnd: THandle; List: TStringList): Bool; StdCall;
Var Buffer: Array[0..255] Of Char;
Begin
SendMessage(wHnd, WM_GETTEXT, 255, LongInt(@Buffer[0]));
If (Buffer <> '') And IsWindow(wHnd) AND IsWindowVisible(wHnd) Then
Begin
List.AddObject(Buffer, TObject(wHnd));
End;
Result := True; //Continue enumerations till false is returned.
End;

And this is what freezes my app...


Enumwindows(@WindowList, LParam(LstWindows.Items));

Does anybody know what the problem is it used to work but then just started freezing up im suspecting windows is being gay but maybe my code is just tempermental.

Alimonster
13-08-2004, 07:41 AM
I don't see a problem with that code. I tried the following on Windows 98 and it worked fine:

function Callback(Window: HWND; List: TStringList): BOOL; stdcall;
var
Buffer: array[0..255] of Char;
begin
SendMessage(Window, WM_GETTEXT, 255, LongInt(@Buffer[0]));
if (Buffer <> '') and IsWindow(Window) and IsWindowVisible(Window) then
begin
List.AddObject(Buffer, TObject(Window));
end;

Result := True;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
List: TStringList;
begin
List := TStringList.Create;
try
EnumWindows(@Callback, Integer(List));
ShowMessage('Finished');
Memo1.Lines.Assign(List);
finally
List.Free;
end;
end;

Anonymous
13-08-2004, 10:13 AM
yeh all of a suddne my app is working again :S it must be certain windows to enumerate or soemthing tht it cant handle not sure how i could permanently fix this though.