|
发表于 2011-11-20 19:52:39
|
显示全部楼层
给你个官方的例子
[au3]#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <misc.au3>
Opt("GuiOnEventMode",1)
Opt("MustDeclareVars",1)
Global $HWNDMAIN, $GUI_W = 800, $GUI_H = 600
Global $HWNDCHILD, $Child_W = 600, $Child_H = 400
Global $activePackage = 0, $activeChildren[1] = [0], $GUI_CTRLID = 0
$HWNDMAIN = GUICreate("Main", $GUI_W, $GUI_H, Default, Default)
GUISetOnEvent($GUI_EVENT_CLOSE,"_Exit")
GUISetState()
$HWNDCHILD = GUICreate("",$Child_W,$Child_H,100, 100, BitOR($WS_POPUP,$WS_BORDER),$WS_EX_MDICHILD,$HWNDMAIN)
GUISetBkColor(0xFFFFBB)
GUISetState()
$activePackage = $HWNDCHILD ;Simulates something from full script
GUIRegisterMsg($WM_WINDOWPOSCHANGING, "WM_WINDOWPOSCHANGING")
_CreateCell($HWNDCHILD, 136, 142 )
_CreateCell($HWNDCHILD, 136, 142 )
While 1
Sleep(250)
WEnd
Func WM_WINDOWPOSCHANGING($hWnd, $Msg, $wParam, $lParam)
ConsoleWrite("WM_WINDOWPOSCHANGING" & @CRLF)
Local $i, $activeCell = 0
For $i = 1 to $activeChildren[0]
If $hWnd = $activeChildren[$i] then
$activeCell = $HWND
ConsoleWrite($activeCell & @CRLF)
ExitLoop
EndIf
Next
If WinActive($HWNDMAIN) then Return
If $hWnd <> $activeCell then Return
If $activePackage = 0 then Return
Local $aMain_Pos = WinGetPos($activePackage) ;Get the position of the ParentCell
If NOT IsArray($aMain_Pos) then Return
Local $aCell_Pos = WinGetPos($HWND) ;<< patch
If NOT IsArray($aCell_Pos) then Return
;Get the position of the window which is currently dragging and specify the drag limits
Local $stWinPos = DllStructCreate("uint;uint;int;int;int;int;uint", $lParam)
Local $iLeft = DllStructGetData($stWinPos, 3)
Local $iTop = DllStructGetData($stWinPos, 4)
Local $iWidth = $aCell_Pos[2] ;<< patch DllStructGetData($stWinPos, 5)
Local $iHeight = $aCell_Pos[3] ;<< patch DllStructGetData($stWinPos, 6)
If DllStructGetData($stWinPos, 5) <> $iWidth then DllStructSetData($stWinPos, 5, $iWidth)
If DllStructGetData($stWinPos, 6) <> $iHeight then DllStructSetData($stWinPos, 6, $iHeight)
Local $iX_Min = $aMain_Pos[0]
Local $iY_Min = $aMain_Pos[1]
Local $iX_Max = ($aMain_Pos[0] + $aMain_Pos[2]) - $iWidth
Local $iY_Max = ($aMain_Pos[1] + $aMain_Pos[3]) - $iHeight
ConsoleWrite("X = " & $iLeft & @CRLF & _
"Y = " & $iTop & @CRLF & _
"W = " & $iWidth & @CRLF & _
"H = " & $iHeight & @crlf)
If $iLeft < $iX_Min Then DllStructSetData($stWinPos, 3, $iX_Min)
If $iLeft > $iX_Max Then DllStructSetData($stWinPos, 3, $iX_Max)
If $iTop < $iY_Min Then DllStructSetData($stWinPos, 4, $iY_Min)
If $iTop > $iY_Max Then DllStructSetData($stWinPos, 4, $iY_Max)
Return $GUI_RUNDEFMSG
EndFunc
Func _CreateCell($vHWND, $w,$h )
Local $HWNDCHILD = GUICreate("",$w, $h, 1, 1, BitOR($WS_POPUP,$WS_BORDER),$WS_EX_MDICHILD,$vHWND)
GUICtrlCreatePic(@ProgramFilesDir & "\AutoIt3\Examples\GUI\Merlin.gif",0,0,$w,$h, $WS_CLIPSIBLINGS ,$GUI_WS_EX_PARENTDRAG)
GUICtrlCreateLabel("",0,0,$w,$h,Default,$GUI_WS_EX_PARENTDRAG)
GUICtrlSetOnEvent(-1,"_MouseClick")
GUICtrlSetBkColor(-1,$GUI_BKCOLOR_TRANSPARENT)
GUISetState()
ReDim $activeChildren[$activeChildren[0] +2]
$activeChildren[$activeChildren[0] +1] = $HWNDCHILD
$activeChildren[0] +=1
Return $HWNDCHILD
EndFunc
Func _MouseClick()
$GUI_CTRLID = @GUI_CtrlId
EndFunc
Func _Exit()
Exit
EndFunc[/au3] |
评分
-
查看全部评分
|