Hi David;
Roland has the correct reply & suggestion.
You can see this feature at work in my framework. Its called the "Window Manager" service and it tracks all open windows regardless of their type. The WM is automatic and hidden and yo do not have to program for it like a PFC service. Not only can you see the open windows at any time ..
Native:
Dockable:
WEB
The framework uses the "Window Manager" service to close all open windows in the exact "reverse" order they were opened when a "Close All" request is made or the App is closing down altogether. The App Manager also produces Window (and its associated Menu) usage stats upon closure. ;-)
Feel free to check out how this works in the STD Integrated Framework's example OrderEntry Demo App ...
https://sourceforge.net/projects/stdfndclass/files/Applications/PowerBuilder/OrderEntry
HTH
Regards ... Chris
PS: This feature works in all Native, PowerServer Web / Mobile, and IWA deployed PB Apps. Also, the framework is free and fully open sourced - so feel free to use this free framework or borrow this code for your framework and/or App directly.