public static IEnumerable <ApplicationWindow> GetApplicationWindows() { List <ApplicationWindow> windows = new List <ApplicationWindow>(); EnumWindowsCallback callback = new EnumWindowsCallback( (hWnd, lParam) => { if (!IsWindowVisible(hWnd) || string.IsNullOrEmpty(GetText(hWnd))) { return(true); } if ((long)GetParent(hWnd) == 0) { bool hasOwner = (long)GetWindow(hWnd, GW_OWNER) != 0; uint exStyle = (uint)GetWindowLongPtr(hWnd, GWL_EXSTYLE); if ((exStyle & WS_EX_TOOLWINDOW) == 0 && !hasOwner) { ApplicationWindow window = new ApplicationWindow(hWnd); windows.Add(window); } } return(true); } ); EnumWindows(callback, IntPtr.Zero); return(windows); }
public static IntPtr Register(Window destination, ApplicationWindow source) { IntPtr thumbnail; IntPtr destinationHandle = new WindowInteropHelper(destination).Handle; if (DwmRegisterThumbnail(destinationHandle, source, out thumbnail) == S_OK) { return(thumbnail); } return(IntPtr.Zero); }