Windows API has the function GetTopWindow GetTopWindow function (Windows)[^] From the TopWindow you want walk down thru the chain via GetNextWindow GetNextWindow function (Windows)[^] So in your case you want to ask the topWindow of the window that contains both FileZilla window and a Notepad Window. You can then walk along the chain using GetNextWindow and see which is above which just by asking the window title. Something like this will work
char buf[256];
HWND Wnd = GetTopWindow( /*handle of window containing both*/ );
GetWindowText(Wnd, &buf[0], sizeof(buf));
while (Wnd != 0 && !stricmp(&buf[0], "FileZilla") && !stricmp(&buf[0], "NotePad"))
{
Wnd = GetNextWindow(Wnd, GW_HWNDNEXT); // Next window
GetWindowText(Wnd, &buf[0], sizeof(buf)); // Get it's title
}
if (Wnd == 0) {
/* Error neither window found */
}
else {
/* Wnd is the topmost of 2 windows title and the string title is in buf */
}
It is equivalent to EnumChildWindows function (Windows)[^] However for the simplicity you have it isn't worth setting up the enumeration function.
In vino veritas