AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Maximize a window either vertically or horizontally
Goto page 1, 2  Next
 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
ranlun



Joined: 19 Jan 2006
Posts: 11

PostPosted: Thu Jan 19, 2006 1:06 pm    Post subject: Maximize a window either vertically or horizontally Reply with quote

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
View user's profile Send private message
Serenity



Joined: 07 Nov 2004
Posts: 1271

PostPosted: Thu Jan 19, 2006 1:40 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
ranlun



Joined: 19 Jan 2006
Posts: 11

PostPosted: Thu Jan 19, 2006 3:21 pm    Post subject: Reply with quote

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
View user's profile Send private message
Serenity



Joined: 07 Nov 2004
Posts: 1271

PostPosted: Thu Jan 19, 2006 11:18 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
ranlun



Joined: 19 Jan 2006
Posts: 11

PostPosted: Fri Jan 20, 2006 7:36 am    Post subject: Reply with quote

Thanks!!
You have been a great help Very Happy
Back to top
View user's profile Send private message
ranlun



Joined: 19 Jan 2006
Posts: 11

PostPosted: Fri Jan 20, 2006 6:45 pm    Post subject: Reply with quote

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
View user's profile Send private message
Serenity



Joined: 07 Nov 2004
Posts: 1271

PostPosted: Fri Jan 20, 2006 7:14 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
ranlun



Joined: 19 Jan 2006
Posts: 11

PostPosted: Fri Jan 20, 2006 7:22 pm    Post subject: Reply with quote

Wink ok. Nice of you to try though, but now it's more work than using the mouse
Back to top
View user's profile Send private message
shimanov



Joined: 25 Sep 2005
Posts: 610

PostPosted: Fri Jan 20, 2006 10:12 pm    Post subject: Re: Maximize a window either vertically or horizontally Reply with quote

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
View user's profile Send private message
ranlun



Joined: 19 Jan 2006
Posts: 11

PostPosted: Sat Jan 21, 2006 12:38 pm    Post subject: Reply with quote

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 Smile
Is it possible?

Thanks for the good help so far.
Back to top
View user's profile Send private message
shimanov



Joined: 25 Sep 2005
Posts: 610

PostPosted: Sun Jan 22, 2006 12:34 am    Post subject: Reply with quote

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
View user's profile Send private message
philc
Guest





PostPosted: Wed Aug 09, 2006 2:56 am    Post subject: Excellent! Reply with quote

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

PostPosted: Wed Aug 09, 2006 5:01 am    Post subject: Conflict with other hotkeys Reply with quote

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
View user's profile Send private message
quatermass



Joined: 14 Dec 2005
Posts: 216

PostPosted: Thu Sep 06, 2007 12:18 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
engunneer



Joined: 30 Aug 2005
Posts: 8255
Location: Maywood, IL

PostPosted: Thu Sep 06, 2007 5:19 pm    Post subject: Reply with quote

Code:

check := WinExist("A")
WinMove, ahk_pid %check%, , (X), (Y), (W), (H)

_________________

(Common Answers)
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group