procedure TForm1.Button1Click(Sender: TObject);
var
WindowText: array[0..255] of char;
TheWindow: HWND;
ThePreviousWindow: HWND;
begin
{get the handle to the Form1 child window at the
top of the Z order relative to its siblings}
TheWindow:=GetTopWindow(Form1.Handle);
{get the text displayed on this window...}
GetWindowText(TheWindow,WindowText,255);
{...and display it in the label}
Label2.Caption:='Top Window: '+WindowText;
{now get the window just under it in the Z order}
ThePreviousWindow:=GetNextWindow(TheWindow,GW_HWNDNEXT);
{get the text displayed on this window...}
GetWindowText(ThePreviousWindow,WindowText,255);
{...and display it in the label}
Label3.Caption:='Next To Top: '+WindowText;
end;