Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

Accurate code to restore minimized windows state


  • Please log in to reply
No replies to this topic

#1 Stilez

Stilez

    Seeker

  • Active Members
  • 18 posts

Posted 31 July 2011 - 08:14 PM

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!

AutoIt         
#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, 31 July 2011 - 08:15 PM.











0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users