Based on the solution found
here I am able to iterate through a list of Application.Current.Windows and close them upon logging out of my system. However, there is a possibility that a Dialog (OpenFileDialog or the like) may be open; unfortunately, this dialog is not in the collection of Current.Windows. Is there any other way to ensure that all such dialogs get closed (without having to store a collection of them somewhere, for instance?)
Based on the solution found here I am able to iterate through a list
Share
To find all the traditional Win32 windows, you will want to enumerate the windows on your thread(s) and close them.
Declarations of some helpful functions and a constant:
You need a delegate declaration for the callback to enum the children:
The callback itself, which closes each window found. You will want to add your own criteria here if there are windows you do not want closed, e.g. your top level window. I’ve added some commented out code below to get the window title, for example.
To do the enumeration: