How can I get the current top window of the system?

But not active or having a focus, but the upper one.

For example, set using the SetWindowPos API function with the second parameter HWND_TOPMOST .

  • poorly imagine how this will work. And if 2 windows expose themselves so? The criterion is not clear. - Alex Kapustin
  • one
    Then one window goes down a level, and the other becomes the top =) I ought to learn some ... - AseN

1 answer 1

Use GetForegroundWindow to get the active window, and the function GetTopWindow (specifying the parent window as 0 (desktop)), or the function GetWindow with the GW_HWNDFIRST parameter to get the top window.

  • GetWindow (NULL, GW_HWNDFIRST); returns 0 GetTopWindow (NULL); seems to return the handle of the top GetForegroundWindow control (NULL); returns the active (focusing) window (even if it is below all, for example, the desktop) - insolor
  • GetTopWindow (NULL) - Error! Does not work ... - AseN
  • I also get an error in Delphi, but not in C. - insolor
  • Although, probably, all the terms have already come out, I will still write. Of course, NULL in Delphi will generate an error, because this is a macro. It is necessary to write 0 . - Pavel Mayorov