Jump to content

Recommended Posts

Posted (edited)

Hey Guys,

I was trying to figure out the best way to restore minimized windows with the following script. I was able to get the windows to restore the the original location but when they are minimized they do no restore. Any help would be greatly appreciated!

#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>

$parentgui=GUICreate("Test", 600, 400)
$windowsave = GUICtrlCreateButton ("Window Save",280,20,80,20)
$windowrestore = GUICtrlCreateButton ("Window Restore",280,40,90,20)
$winlist = WinList()
GUISetState(@SW_SHOW)

;WINDOWS Save

While 1
    $iMsg = GUIGetMsg()

    Switch $iMsg

      GUISetState(@SW_SHOW)


Case $GUI_EVENT_CLOSE
Exit

Case $windowsave
StoreWins()
msgbox (0,"Your Windws Have Been Saved, Ok to Remove from Dock", "Your Windows Have Been Saved, OK to Remove from Dock")

Case $windowrestore
WinSetState($winlist,"",@SW_RESTORE)
RestoreWins()




EndSwitch
Wend

Func StoreWins($file = "windows.ini")
    Local $var = WinList()
    If FileExists($file) Then FileDelete($file)
    For $i = 1 to $var[0][0]
      If IsVisible($var[$i][1]) Then
        Local $pos = WinGetPos($var[$i][1])
        IniWrite($file, Binary($var[$i][0]), "x", $pos[0])
        IniWrite($file, Binary($var[$i][0]), "y", $pos[1])
        IniWrite($file, Binary($var[$i][0]), "w", $pos[2])
        IniWrite($file, Binary($var[$i][0]), "h", $pos[3])
      EndIf
    Next
EndFunc

Func RestoreWins($file = "windows.ini")
    Local $var = WinList()
    For $i = 1 to $var[0][0]
      If IsVisible($var[$i][1]) Then
        If IniRead($file, $var[$i][0], "x", False) Then
            Local $pos = WinGetPos($var[$i][1])
            WinMove($var[$i][0], "", IniRead($file, Binary($var[$i][0]), "x", $pos[0]), IniRead($file, Binary($var[$i][0]), "y", $pos[1]), IniRead($file, Binary($var[$i][0]), "w", $pos[2]), IniRead($file, Binary($var[$i][0]), "h", $pos[3]))
        EndIf
     EndIf

    Next
EndFunc

Func IsVisible($handle)
    Return BitAnd(WinGetState($handle), 2)
EndFunc
Edited by mlewis412
Posted

Thanks for the response FireFox.

However I was able to accomplish what I was looking for using the following:

$aWinList=WinList()For $i=1 to $aWinList[0][0]    If 
$aWinList[$i][0]<> "" And  $aWinList[$i][0]<>"" And 
_        
BitAND(WinGetState($aWinList[$i][1]),16)=16 Then 
WinSetState($aWinList[$i][1],"",@SW_RESTORE)Next
Posted

Well Shocks!  Firefox. I think your right and  I see why you referenced _WinAPI_GetWindowPlacement .

 

But shouldnt I be able to get around that by using the following.. Basically whats happening is the minimized windows will restore, but appears they are restoring to 112 x 27 pixels as stated in the WinMove.

My thought was to first restore all windows and then place them back in their original position.

Here is the script I am working with now for your review (The GUI's position can remain static as shown in the code):

#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>
 #include <WinAPI.au3>
 #include <Array.au3>

$parentgui=GUICreate("Test", 600, 400)
$windowsave = GUICtrlCreateButton ("Window Save",280,20,80,20)
$windowrestore = GUICtrlCreateButton ("Window Restore",280,40,90,20)
$winlist = WinList()
GUISetState(@SW_SHOW)

;WINDOWS Save

While 1
    $iMsg = GUIGetMsg()

    Switch $iMsg

      GUISetState(@SW_SHOW)


Case $GUI_EVENT_CLOSE
Exit

Case $windowsave
StoreWins()
msgbox (0,"Your Windws Have Been Saved, Ok to Remove from Dock", "Your Windows Have Been Saved, OK to Remove from Dock")

Case $windowrestore
Max ()
RestoreWins()
WinMove($parentgui, "", 0, 0, 600, 400)



EndSwitch
Wend

Func StoreWins($file = "windows.ini")
    Local $var = WinList()
    If FileExists($file) Then FileDelete($file)
    For $i = 1 to $var[0][0]
      If IsVisible($var[$i][1]) Then
        Local $pos = WinGetPos($var[$i][1])
        IniWrite($file, Binary($var[$i][0]), "x", $pos[0])
        IniWrite($file, Binary($var[$i][0]), "y", $pos[1])
        IniWrite($file, Binary($var[$i][0]), "w", $pos[2])
        IniWrite($file, Binary($var[$i][0]), "h", $pos[3])
      EndIf
    Next
EndFunc

Func RestoreWins($file = "windows.ini")
    Local $var = WinList()
    For $i = 1 to $var[0][0]
      If IsVisible($var[$i][1]) Then
        If IniRead($file, $var[$i][0], "x", False) Then
            Local $pos = WinGetPos($var[$i][1])
            WinMove($var[$i][0], "", IniRead($file, Binary($var[$i][0]), "x", $pos[0]), IniRead($file, Binary($var[$i][0]), "y", $pos[1]), IniRead($file, Binary($var[$i][0]), "w", $pos[2]), IniRead($file, Binary($var[$i][0]), "h", $pos[3]))
        EndIf
     EndIf

    Next
EndFunc

Func IsVisible($handle)
    Return BitAnd(WinGetState($handle), 2)
EndFunc

Func Max()
$aWinList=WinList()
For $i=1 to $aWinList[0][0]
    If $aWinList[$i][0]<> "" And  $aWinList[$i][0]<>"" And _
        BitAND(WinGetState($aWinList[$i][1]),16)=16 Then WinSetState($aWinList[$i][1],"",@SW_RESTORE)
Next
EndFunc
Posted (edited)

If the window is minimized, you can get its normal position coords with the following :

$tRET = _WinAPI_GetWindowPlacement($hWhd)

DllStructGetData($tRET, "rcNormalPosition", 1) ;left
DllStructGetData($tRET, "rcNormalPosition", 2) ;top
DllStructGetData($tRET, "rcNormalPosition", 3) ;right
DllStructGetData($tRET, "rcNormalPosition", 4) ;bottom
So basically, in your For loop, after the IsVisible function, check if the window is minimized and if it's the case, use the GetWindowPlacement instead of the WinGetPos function.

Don't forget that to get the width it's "right-left" and the height it's "top-bottom".

 

Br, FireFox

Edited by FireFox
Posted

Will it restore the normal position in this regard:

Lets say I click Save Window with the window being maximized,

I then minimize the window and click restore window.

 

I am thinking no unless i throw this in both the StoreWins Function and the Restore Wins Function some how correct?

Posted

I don't understand what you mean.

However, if the window is minimized, I don't know if you can get the previous state of the window (either normal or maximized), in this case it will restore it in normal position.

Br, FireFox.

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...