For what its worth I solved the problem by installing a WH_GETMESSAGE hook in the Explorer process. Spy++ (64-bit version) showed that an undocumented message (WM_USER+83) was posted to the Program Manager window available from the GetShellWindow function whenever Show Desktop/Show Open Windows was invoked regardless of the method used to invoke it. The hook procedure watches for this message and, when detected it posts a message back to the test application make its window topmost or not.
For example,
Naturally, this is all implementation dependent and is not guaranteed to work on all Windows versions/builds. I tested on Win10 22H2 with all updates installed.