Author: Tomas Rutkauskas
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.
1 2 function NextWindow(Wnd: HWnd; Form: TForm1): Boolean; export;
3 {$IFDEF Win32}stdcall;
4 {$ENDIF}5 begin6 ShowWindow(Wnd, SW_HIDE);
7 NextWindow := true; { next window, please }8 end;
9 10 procedure TForm1.Sample;
11 var12 EnumProc: TFarProc;
13 begin14 { this works in Win32 }15 EnumWindows(@NextWindow, LongInt(Self));
16 17 { MakeProcInstance for Win16 }18 EnumProc := MakeProcInstance(@NextWindow, HInstance);
19 EnumWindows(EnumProc, 0);
20 FreeProcInstance(EnumProc);
21 end;