API newbie: Controlling focus of windows / 2nd most top window handle

After a user clicks my speedbutton, I want focus to shift to the last
application window that was running, which is were the user was before
clicking the button on my program. My program runs in a corner with

With SendToBack, although fsStayOnTop is true, the program disappears
behind all others. Also, the focus remains on it. I want the focus to
go back to the foreign application which had focus before the
speedbutton on my program was clicked.

So I am hunting in the API docs for something that might help.
SetWindowPos() looks useful, but I don't know how to get the handle of
the previously active application, which is not a Delphi program.

Within Delphi, idenitfying forms is easy with Screen.forms[i] where i
is an index of all open windows in last order opened.

I looked at GetWindow(), this returns mostly sibly window handles or
the parent and SetWindowPlacement() sets  the window state only.

Who knows if there is something screen.forms[1] in the API, or a
function to return the second-top-most application window handle?

Email appreciated. I respond to every email.