2004. január 8., csütörtök
Traverse the global list of all windows
Problem/Question/Abstract:
Traverse the global list of all windows
Answer:
Sometimes you may want to do something with all windows (and controls) on the screen, including non-Delphi windows.
For such a purpose, you will use the API function EnumWindows. The following code includes the calls MakeProcInstance/ FreeProcInstance, which are needed in 16bit-Windows (including Delphi 1 under Win95).
This sample code hides every existing window.. a rather useless example, but after all, it's just an example.
function NextWindow(Wnd: HWnd; Form: TForm1): Boolean; export;
{$IFDEF Win32} stdcall;
{$ENDIF}
begin
ShowWindow(Wnd, SW_HIDE);
NextWindow := true; { next window, please }
end;
procedure TForm1.Sample;
var
EnumProc: TFarProc;
begin
{ this works in Win32 }
EnumWindows(@NextWindow, LongInt(Self));
{ MakeProcInstance for Win16 }
EnumProc := MakeProcInstance(@NextWindow, HInstance);
EnumWindows(EnumProc, 0);
FreeProcInstance(EnumProc);
end;
Feliratkozás:
Megjegyzések küldése (Atom)
Nincsenek megjegyzések:
Megjegyzés küldése