 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
ranlun
Joined: 19 Jan 2006 Posts: 11
|
Posted: Thu Jan 19, 2006 1:06 pm Post subject: Maximize a window either vertically or horizontally |
|
|
Hi.
I want a hotkey to maximize a window horizontally or vertically.
Is it possible? I haven't seen any options for it in the winmax function.
Also I would like to toggle between maximize and restore with the press of a singel hotkey. But how?
Please help me. |
|
| Back to top |
|
 |
Serenity
Joined: 07 Nov 2004 Posts: 1271
|
Posted: Thu Jan 19, 2006 1:40 pm Post subject: |
|
|
Hi ranlun, try the following:
| Code: | ; Get maximised window size
sysget, SM_CXMAXIMIZED, 61
sysget, SM_CYMAXIMIZED, 62
; Get 3D border size
sysget, SM_CXEDGE, 45
sysget, SM_CYEDGE, 46
return
1::
; maxwidth
WinGetClass, class, A
WinGetPos, X, Y, W, H, A
WinMove, ahk_class %class%, , (0-(SM_CXEDGE*2)), (Y), (SM_CXMAXIMIZED)
return
2::
; maxheight
WinGetClass, class, A
WinGetPos, X, Y, W, H, A
WinMove, ahk_class %class%, , (X), (0-(SM_CYEDGE*2)), (W), (SM_CYMAXIMIZED)
return
3::
; restore original size
WinMove, ahk_class %class%, , (X), (Y), (W), (H)
return |
_________________ "Anything worth doing is worth doing slowly." - Mae West
 |
|
| Back to top |
|
 |
ranlun
Joined: 19 Jan 2006 Posts: 11
|
Posted: Thu Jan 19, 2006 3:21 pm Post subject: |
|
|
Thanks!!
One question. I would like that restore window function to quick in if the window is manipulated.
So if I press win+x I maximize it, if I press win+x again, it gets restored.
Is that possible?
Do you know of anyone who has tried to make a virtual dekstop application using autohotkey? |
|
| Back to top |
|
 |
Serenity
Joined: 07 Nov 2004 Posts: 1271
|
Posted: Thu Jan 19, 2006 11:18 pm Post subject: |
|
|
The following script will toggle the active window between maxwidth and original size:
| Code: | ; Get maximised window size
sysget, SM_CXMAXIMIZED, 61
sysget, SM_CYMAXIMIZED, 62
; Get 3D border size
sysget, SM_CXEDGE, 45
sysget, SM_CYEDGE, 46
return
#x::
; toggle between maximised and normal state
WinGetClass, class, A
if flag = max
{
WinMove, ahk_class %class%, , (X), (Y), (W), (H)
flag = min
}
else
{
WinGetPos, X, Y, W, H, A
WinMove, ahk_class %class%, , (0-(SM_CXEDGE*2)), (Y), (SM_CXMAXIMIZED) ; maxwidth
; WinMove, ahk_class %class%, , (X), (0-(SM_CYEDGE*2)), (W), (SM_CYMAXIMIZED) ; maxheight
flag = max
}
return |
| ranlun wrote: | | Do you know of anyone who has tried to make a virtual dekstop application using autohotkey? |
I'm not sure if anyone has yet, you could try searching the forum. _________________ "Anything worth doing is worth doing slowly." - Mae West
 |
|
| Back to top |
|
 |
ranlun
Joined: 19 Jan 2006 Posts: 11
|
Posted: Fri Jan 20, 2006 7:36 am Post subject: |
|
|
Thanks!!
You have been a great help  |
|
| Back to top |
|
 |
ranlun
Joined: 19 Jan 2006 Posts: 11
|
Posted: Fri Jan 20, 2006 6:45 pm Post subject: |
|
|
hmmm.
When I press the hotkey i toggle the windows to max, if I press it again they bacome max horizontal or max vertical. It's strange... |
|
| Back to top |
|
 |
Serenity
Joined: 07 Nov 2004 Posts: 1271
|
Posted: Fri Jan 20, 2006 7:14 pm Post subject: |
|
|
| ranlun wrote: | hmmm.
When I press the hotkey i toggle the windows to max, if I press it again they bacome max horizontal or max vertical. It's strange... |
The script works best if you unmaximise the target window first, otherwise it will toggle between the maxwidth and maximised states. I'm not sure if it's possible to get the unmaximised dimensions of a window whilst it is maximised.
Another "bug" is that you should restore the target window to its original size via the hotkey before switching to another window because the hotkey will apply the previous window size and position to the new active window. _________________ "Anything worth doing is worth doing slowly." - Mae West
 |
|
| Back to top |
|
 |
ranlun
Joined: 19 Jan 2006 Posts: 11
|
Posted: Fri Jan 20, 2006 7:22 pm Post subject: |
|
|
ok. Nice of you to try though, but now it's more work than using the mouse |
|
| Back to top |
|
 |
shimanov
Joined: 25 Sep 2005 Posts: 610
|
Posted: Fri Jan 20, 2006 10:12 pm Post subject: Re: Maximize a window either vertically or horizontally |
|
|
| ranlun wrote: | | singel hotkey |
Do you want a single hotkey to switch between each of the four states (original, max width, max height, max both)?
If not, try this:
| 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
WinMove, A,, 0,, work_area?w
return
F2:: ; maximize height
WinMove, A,,, 0,, work_area?h
return
F3:: ; toggle maximize/restore
if ( DllCall( "IsZoomed", "uint", WinExist( "A" ) ) )
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
}
|
|
|
| Back to top |
|
 |
ranlun
Joined: 19 Jan 2006 Posts: 11
|
Posted: Sat Jan 21, 2006 12:38 pm Post subject: |
|
|
Great! Now that worked!!!
I have copied the whole thing and the restore function worked!!!
How do I make the max vertical and max horizontal restore as well?
I want to be able to have a hotkey for each. One for max, one for max ver and one for max hor. And they should all toggle as well
Is it possible?
Thanks for the good help so far. |
|
| Back to top |
|
 |
shimanov
Joined: 25 Sep 2005 Posts: 610
|
Posted: Sun Jan 22, 2006 12:34 am Post subject: |
|
|
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
}
|
|
|
| Back to top |
|
 |
philc Guest
|
Posted: Wed Aug 09, 2006 2:56 am Post subject: Excellent! |
|
|
| This.... is a great script! Exactly what I was looking for, works just like in Gnome! Good job. |
|
| Back to top |
|
 |
philc
Joined: 09 Aug 2006 Posts: 2
|
Posted: Wed Aug 09, 2006 5:01 am Post subject: Conflict with other hotkeys |
|
|
It seems like this script has to be first in the file, and does not work when other keys are on the same modifier.
For instance, if you change the hotkey F2 to be ctrl z (^z), and then declare another hotkey that uses ctrl ahead of this script, the vertical maximization will simply move the window to the top of the screen instead of maximizing it.
In summary:
^b::Reload
#include maximize.ini
doesn't work. Is it an easy fix to be able to change the hotkeys in this script to make use of modifiers? |
|
| Back to top |
|
 |
quatermass
Joined: 14 Dec 2005 Posts: 216
|
Posted: Thu Sep 06, 2007 12:18 pm Post subject: |
|
|
It would be nicer if the script recorded the pid of the window (instead of class) with its X,Y, W, H dimensions into an array when the key is pressed and then when the key is pressed again it looked for a matching recorded pid and if found used those dimensions.
This would ensure it restored the same window with the old dimensions?
I tried using:
| Code: |
check := WinExist("A")
|
to get the pid, but using
| Code: |
WinMove, ahk_pid %class%, , (X), (Y), (W), (H)
|
didn't move it!
oh hum.. _________________ Stuart Halliday |
|
| Back to top |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 8255 Location: Maywood, IL
|
Posted: Thu Sep 06, 2007 5:19 pm Post subject: |
|
|
| Code: |
check := WinExist("A")
WinMove, ahk_pid %check%, , (X), (Y), (W), (H)
|
_________________
(Common Answers) |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|