#include <WinAPI.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <StaticConstants.au3>
#include <ButtonConstants.au3>
Opt("GUIOnEventMode", 1)
Local $k
$Form1 = GUICreate("拉伸控件", 623, 444, 192, 124)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked") ;
$Button1 = GUICtrlCreateButton("", 192, 144, 185, 89,$BS_BITMAP,$BS_PUSHBOX) ;这个按钮可拉伸
GUISetState(@SW_SHOW)
While 1
Sleep(1)
$GUICur = GUIGetCursorInfo($Form1)
If $GUICur[4] = 3 And $GUICur[2] = 1 Then
lashen()
EndIf
WEnd
Func lashen()
$k = 1
$Ctr = ControlGetPos("拉伸控件","",$Button1) ;控件信息
$nPos = WinGetPos("拉伸控件") ;主窗信息
;-------------------------------------------------------------------------------右边拉伸
$S71 = ($GUICur[0] >= $Ctr[0] + $Ctr[2]- 8) ; 右边
$S72 = ($GUICur[0] <= $Ctr[0] + $Ctr[2]+ 8) ; 右边
If $S71 And $S72 Then
;这里要加一个拖拽的条件
If $k = 1 Then
ControlMove ("拉伸控件","", $Button1,$Ctr[0],$Ctr[1],$GUICur[0]+4-$Ctr[0],$Ctr[3])
EndIf
EndIf
;-------------------------------------------------------------------------------底边拉伸
$S81 = ($GUICur[1] >= $Ctr[1] + $Ctr[3]- 8) ; 底边
$S82 = ($GUICur[1] <= $Ctr[1] + $Ctr[3]+ 8) ; 底边
If $S81 And $S82 Then
If $k = 1 Then
ControlMove ("拉伸控件","", $Button1,$Ctr[0],$Ctr[1],$Ctr[2],$GUICur[1]+4-$Ctr[1])
EndIf
EndIf
;------------------------------------------------------------------------------左边拉伸
$S51 = ($GUICur[0] <= $Ctr[0]+ 8) ; 左边
$S52 = ($GUICur[0] >= $Ctr[0]- 8) ; 左边
If $S51 And $S52 Then
If $k = 1 Then
ControlMove ("拉伸控件","", $Button1,$GUICur[0]-4,$Ctr[1],$Ctr[2]-($GUICur[0]-4-$Ctr[0]),$Ctr[3]) ControlMove ("拉伸控件","", $Button1,$GUICur[0]-4,$Ctr[1],$Ctr[2]-($GUICur[0]-4-$Ctr[0]),$Ctr[3])
EndIf
EndIf
;---------------------------------------------------------------------------------上边拉伸
$S61 = ($GUICur[1] <= $Ctr[1]+ 8) ; 上边
$S62 = ($GUICur[1] >= $Ctr[1]- 8) ; 上边
If $S61 And $S62 Then
If $k = 1 Then
ControlMove ("拉伸控件","", $Button1,$Ctr[0],$GUICur[1]-4,$Ctr[2],$Ctr[3]-($GUICur[1]-4-$Ctr[1]))
EndIf
EndIf
;-----------------------------------------------------------------------------------
$S1x1 = ($GUICur[0] >= $Ctr[0]+ $Ctr[2]- 8) ; 右下角x
$S1x2 = ($GUICur[0] <= $Ctr[0]+ $Ctr[2]+ 8) ; 右下角x
$S1y1 = ($GUICur[1] >= $Ctr[1]+ $Ctr[3]- 8) ; 右下角y
$S1y2 = ($GUICur[1] <= $Ctr[1]+ $Ctr[3]+ 8) ; 右下角y
If $S1x1 and $S1x2 and $S1y1 and $S1y2 Then
If $k = 1 Then
ControlMove ("拉伸控件","", $Button1,$Ctr[0],$Ctr[1],$GUICur[0]+4-$Ctr[0],$GUICur[1]+4-$Ctr[1])
EndIf
EndIf
;------------------------------------------------------------------------------------
$S2x1 = ($GUICur[0] <= $Ctr[0]+ 8) ; 左上角x
$S2x2 = ($GUICur[0] >= $Ctr[0]- 8) ; 左上角x
$S2y1 = ($GUICur[1] <= $Ctr[1]+ 8) ; 左上角y
$S2y2 = ($GUICur[1] >= $Ctr[1]- 8) ; 左上角y
If $S2x1 and $S2x2 and $S2y1 and $S2y2 Then
If $k = 1 Then
ControlMove ("拉伸控件","", $Button1,$GUICur[0]-4,$GUICur[1]-4,$Ctr[2]-($GUICur[0]-4-$Ctr[0]),$Ctr[3]-($GUICur[1]-4-$Ctr[1]))
EndIf
EndIf
;------------------------------------------------------------------------------------
$S3x1 = ($GUICur[0] <= $Ctr[0]+8) ; 左下角x
$S3x2 = ($GUICur[0] >= $Ctr[0]-8) ; 左下角x
$S3y1 = ($GUICur[1] >= $Ctr[1]+ $Ctr[3]- 8) ; 左下角y
$S3y2 = ($GUICur[1] <= $Ctr[1]+ $Ctr[3]+ 8) ; 左下角y
If $S3x1 and $S3x2 and $S3y1 and $S3y2 Then
If $k = 1 Then
ControlMove ("拉伸控件","", $Button1,$GUICur[0]-4,$Ctr[1],$Ctr[2]-($GUICur[0]-4-$Ctr[0]),$GUICur[1]+4-$Ctr[1])
EndIf
EndIf
;------------------------------------------------------------------------------------
$S4x1 = ($GUICur[0] >= $Ctr[0]+ $Ctr[2]- 8) ; 右上角x
$S4x2 = ($GUICur[0] <= $Ctr[0]+ $Ctr[2]+ 8) ; 右上角x
$S4y1 = ($GUICur[1] <= $Ctr[1]+ 8) ; 右上角y
$S4y2 = ($GUICur[1] >= $Ctr[1]- 8) ; 右上角y
If $S4x1 and $S4x2 and $S4y1 and $S4y2 Then
If $k = 1 Then
ControlMove ("拉伸控件","", $Button1,$Ctr[0],$GUICur[1]-4,$GUICur[0]+4-$Ctr[0],$Ctr[3]-($GUICur[1]-4-$Ctr[1]))
EndIf
EndIf
EndFunc
Func CLOSEClicked()
GUIDelete($Form1)
Exit
EndFunc