热键循环切换当前窗口为1/4、1/3、2/3屏幕大小

;脚本功能是调整当前窗口的大小
;sunwind 
;2013年8月25日

;需求是多爱英提出,我用了面向对象的ahk来实现的。
;~ 按一下热键(win+z)
;~ 切换到  右下角1/4
;~ 再按一下
;~ 切换到  右下角 1/3
;~ 再按一下 
;~ 切换到 右下角 2/3
;~ 再按一下
;~ 切换到  右下角 1/4
SetTitleMatchMode, 3
event_index:=-1
#z::
WinGetTitle, current_win, A
if (current_win!=old_win)
	event_index=-1
if(event_index=-1)
{
	old_win:=current_win
	WinGetPos, X, Y, current_Width, current_Height, %current_win%  ;这里A应该改成目标窗口,只获取一次某窗口的大小
  	;quarter := new quarter(current_Width,current_Height)
  	;one_third:= new one_third(current_Width,current_Height)
  	;two_third:= new two_third(current_Width,current_Height)
  	;若针对窗体而不是屏幕则解除上面注释 并给窗体值

  	;用SysGet, MonitorWorkArea,而未用A_ScreenWidth A_ScreenHeight 避免任务条的影响
  	SysGet, MonitorWorkArea, MonitorWorkArea,1
  	;MsgBox, Monitor:`t`nLeft:`t%MonitorLeft% (%MonitorWorkAreaLeft% work)`nTop:`t%MonitorTop% (%MonitorWorkAreaTop% work)`nRight:`t%MonitorRight% (%MonitorWorkAreaRight% work)`nBottom:`t%MonitorBottom% (%MonitorWorkAreaBottom% work)
  	quarter := new quarter(MonitorWorkAreaRight ,MonitorWorkAreaBottom)
  	one_third:= new one_third(MonitorWorkAreaRight ,MonitorWorkAreaBottom)
  	two_third:= new two_third(MonitorWorkAreaRight ,MonitorWorkAreaBottom)
}
	event_index+=1
	event_index:=Mod(event_index, 3)  ;3个状态循环,模3,模运算得出 0,1,2
	commandArray := ["quarter", "one_third", "two_third"]
    runner:=commandArray[event_index+1] ;因为ahk的数组是从1开始的,对于索引为0时是空值,加一避免此问题
  	%runner%.zoom()
  	;TrayTip, %current_win%缩放%runner%,% "w=" %runner%.getNewWidth()  ",h="  %runner%.getNewHeight() , 10,
  	NewWidth:=%runner%.getNewWidth() 
  	NewHeight:=%runner%.getNewHeight()
  	WinMove, %current_win%,,MonitorWorkAreaRight-NewWidth,MonitorWorkAreaBottom-NewHeight,NewWidth,NewHeight
Return

class WinSize
{
   Width :=0
   Height := 0
   NewWidth:=0
   NewHeight:=0
   ;SetWidth(val){
   ;   Width := val ; Can set the color using a function of the class
   ;}
   ;SetHeight(val){
   ;   Height := val ; Can set the color using a function of the class
   ;}
   GetWidth(){
      Return this.Width ;需要增加this
   }

   GetHeight(){
      Return this.Height  ;需要增加this
   }

   GetNewWidth(){
      Return this.NewWidth ;需要增加this
   }
   GetNewHeight(){
      Return this.NewHeight  ;需要增加this
   }
	__New(w="",h=""){
		if (w="")
			this.Width :=A_ScreenWidth
		Else
			this.Width :=w		
		if (h="")	
			this.Height:=A_ScreenHeight
		Else
			this.Height := h
	}
}

Class half extends WinSize{
	zoom()
	{
		this.NewWidth:=  this.Width//2  ;向下舍除 (//)
		this.NewHeight:=  this.Height
	}
}

Class quarter extends WinSize{
	zoom()
	{
		this.NewWidth:=  this.Width//2
		this.NewHeight:=  this.Height//2
	}
}

Class one_third extends WinSize{
	zoom()
	{
		this.NewWidth:= this.Width//3
		this.NewHeight:= this.Height
	}
}

Class two_third extends WinSize{
	zoom()
	{
		this.NewWidth:= this.Width*2//3
		this.NewHeight:= this.Height
	}	
}


原文地址:https://www.cnblogs.com/james1207/p/3281422.html