Updated to save state:
Code:
VarSetCapacity( work_area, 16 )
DllCall( "SystemParametersInfo"
, "uint", 0x30 ; SPI_GETWORKAREA
, "uint", 0
, "uint", &work_area
, "uint", 0 )
work_area?w := DecodeInteger( "int4", &work_area, 8, false )-DecodeInteger( "int4", &work_area, 0, false )
work_area?h := DecodeInteger( "int4", &work_area, 12, false )-DecodeInteger( "int4", &work_area, 4, false )
return
F1:: ; maximize width
F2:: ; maximize height
F3:: ; toggle maximize/restore
WinGet, hw_active, ID, A
WinGetPos, a_x, a_y, a_w, a_h, A
if windows[%hw_active%]=
{
windows[%hw_active%] := true
windows[%hw_active%]?x := a_x
windows[%hw_active%]?y := a_y
windows[%hw_active%]?w := a_w
windows[%hw_active%]?h := a_h
windows[%hw_active%]?max_w := false
windows[%hw_active%]?max_h := false
}
if A_ThisHotkey in F1,F2
{
if ( DllCall( "IsZoomed", "uint", hw_active ) )
WinRestore, A
if ( A_ThisHotkey = "F1" )
{
if ( windows[%hw_active%]?max_w )
WinMove, A,, windows[%hw_active%]?x,, windows[%hw_active%]?w
else
WinMove, A,, 0,, work_area?w
windows[%hw_active%]?max_w := !windows[%hw_active%]?max_w
}
else if ( A_ThisHotkey = "F2" )
{
if ( windows[%hw_active%]?max_h )
WinMove, A,,, windows[%hw_active%]?y,, windows[%hw_active%]?h
else
WinMove, A,,, 0,, work_area?h
windows[%hw_active%]?max_h := !windows[%hw_active%]?max_h
}
}
else if ( A_ThisHotkey = "F3" )
{
if ( DllCall( "IsZoomed", "uint", hw_active ) )
WinRestore, A
else
WinMaximize, A
}
return
DecodeInteger( p_type, p_address, p_offset, p_hex=true )
{
old_FormatInteger := A_FormatInteger
if ( p_hex )
SetFormat, Integer, hex
else
SetFormat, Integer, dec
sign := InStr( p_type, "u", false )^1
StringRight, size, p_type, 1
loop, %size%
value += ( *( ( p_address+p_offset )+( A_Index-1 ) ) << ( 8*( A_Index-1 ) ) )
if ( sign and size <= 4 and *( p_address+p_offset+( size-1 ) ) & 0x80 )
value := -( ( ~value+1 ) & ( ( 2**( 8*size ) )-1 ) )
SetFormat, Integer, %old_FormatInteger%
return, value
}