Sign in to follow this  
Followers 0

Accurate code to restore minimized windows state

1 post in this topic

Posted (edited)

I was playing round with WinMinimizeAll() and WinMinimizeAllUndo(). If you have popup dialogs etc in between, sometimes the WinMinimizeAllUndo() "forgets" which windows were minimized by WinMinimizeAll() so it doesn't do the restore function as you'd expect.

For anyone who hits this, the following code will handle it - and allow arbitrary window manipulation in between. It logs all non-minimized window handles, and when you're done, it checks for any windows that are displayed now, were displayed before (according to its handle) and whose state has changed from non-minimized to minimized, and restores it.

Things it doesn't do - it doesn't handle clashes of window handles, and it doesn't remember the active window (their Z-order). If anyone wants to fix for those, please do!

#Include <Array.au3>


dim $OriginalNonMinimizedWindows[1]
$OriginalNonMinimizedWindows[0]=""

$winlist  = WinList()
If $winlist[0][0] > 0 Then
	for $i = 1 to $winlist[0][0]
		$winhdl = $winlist[$i][1]
		$state = WinGetState($winhdl)
		If BitAND($state,16) <> 16 Then _ArrayAdd($OriginalNonMinimizedWindows, $winhdl)
	Next
EndIf
_ArraySort($OriginalNonMinimizedWindows)

WinMinimizeAll()
sleep (1500)

$winlist = Winlist()
If $winlist[0][0] > 0 Then
	For $i = 1 to $winlist[0][0]
		$winhdl = $winlist[$i][1]
		$state = WinGetState($winhdl)
		If BitAND($state, 16) == 16 Then
			If _ArrayBinarySearch($OriginalNonMinimizedWindows, $winhdl) >= 0 Then 
				WinSetState($winhdl, "", @SW_RESTORE)
				msgbox(1,"","Restored window for: " & $winlist[$i][0] & " (handle "& $winlist[$i][1] & ").", 1)
			EndIf
		EndIf
	Next
EndIf
Edited by Stilez

Share this post


Link to post
Share on other sites



Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.