回复 15# xms77
第一个是取控件id,第二个是取消息值
最大化后再最小化,位置越来越高,还是因为变量$movey没有置0的缘故,干脆不要这个变量了,试试下面的代码,可能还会有问题,并没有严格测试
#include <GuiConstants.au3>
#include <WindowsConstants.au3>
#include <GuiStatusBar.au3>
#include <winapi.au3>
Global Const $SC_CLOSE = 0xF060
Global Const $SC_MINIMIZE = 0xF020
Global Const $SC_RESTORE = 0xF120
Global Const $SC_MAXIMIZE = 0xF030
Global $MoveForm
Local $ChildForm[1] = [0], $ChildBtn[1] = [0]
$MainForm = GUICreate("Main", 700, 500, -1, -1, BitOR($WS_SIZEBOX, $WS_MINIMIZEBOX, $WS_MAXIMIZEBOX, $WS_CAPTION, $WS_SYSMENU))
$menu = GUICtrlCreateMenu("窗口")
$new1 = GUICtrlCreateMenuItem("新建", $menu)
$new2 = GUICtrlCreateMenuItem("批量新建", $menu)
GUICtrlCreateMenuItem("", $menu)
$mini = GUICtrlCreateMenuItem("全部最小化", $menu)
GUICtrlCreateMenuItem("", $menu)
$RESTORE = GUICtrlCreateMenuItem("全部还原", $menu)
GUICtrlCreateMenuItem("", $menu)
$close = GUICtrlCreateMenuItem("全部关闭", $menu)
Local $aText[2] = ["AU3子窗口最小化", @TAB & "Crossdoor"]
Local $aParts[2] = [170, -1]
$hStatus = _GUICtrlStatusBar_Create($MainForm, $aParts, $aText, 0x54000000, 0x00000000)
GUISetState(@SW_SHOW, $MainForm)
$iStatusHeight = _GUICtrlStatusBar_GetHeight($hStatus)
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
GUIRegisterMsg($WM_SYSCOMMAND, "WM_SYSCOMMAND")
GUIRegisterMsg($WM_WINDOWPOSCHANGING, "WM_WINDOWPOSCHANGING")
While 1
Sleep(2500)
WEnd
Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
$iControl = BitAND($iwParam, 0xFFFF)
$iMsg = BitShift($iwParam, 16)
Switch $iControl
Case $new1;新建子窗口
_CreateChildForm()
Case $new2;批量新建子窗口
For $i = 0 To Random(3, 10, 1)
_CreateChildForm()
Next
Case $close;关闭全部子窗口
_CloseChildForm()
Case $mini;最小化全部子窗口
For $i = 0 To UBound($ChildForm) - 1
_SendMessageA($ChildForm[$i], $WM_SYSCOMMAND, $SC_MINIMIZE)
;~ GUISetState(@SW_MINIMIZE, $ChildForm[$i])
Next
Case $RESTORE
For $i = 0 To UBound($ChildForm) - 1
_SendMessageA($ChildForm[$i], $WM_SYSCOMMAND, $SC_RESTORE)
;~ GUISetState(@SW_RESTORE, $ChildForm[$i])
Next
Case Else;子窗口按钮点击
For $i = 0 To UBound($ChildBtn) - 1
If $iMsg = 0 And $iControl = $ChildBtn[$i] Then
Return MsgBox(0, WinGetTitle($hWnd) & " 提示", "我是[" & $i & "]窗口。" & @CRLF & "我的句柄是:" & $ChildForm[$i], 0, $ChildForm[$i])
EndIf
Next
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_COMMAND
Func WM_SYSCOMMAND($hWnd, $Msg, $wParam, $lParam)
Local $iID = BitAND($wParam, 0x0000FFFF)
Switch $iID
Case $SC_CLOSE
If $hWnd = $MainForm Then
_CloseChildForm()
Exit
Else
For $i = 0 To UBound($ChildForm) - 1
If $ChildForm[$i] = $hWnd Then
GUIDelete($ChildForm[$i])
$ChildForm[$i] = 0
ExitLoop
EndIf
Next
EndIf
Case $SC_MINIMIZE
If $hWnd <> $MoveForm Then
$MoveForm = $hWnd
EndIf
EndSwitch
EndFunc ;==>WM_SYSCOMMAND
Func WM_WINDOWPOSCHANGING($hWnd, $Msg, $wParam, $lParam)
If $hWnd == $MoveForm Then
Local $rect, $x, $y, $width, $height
$rect = DllStructCreate($tagWINDOWPOS, $lParam)
$x = DllStructGetData($rect, "X")
$y = DllStructGetData($rect, "Y")
$width = DllStructGetData($rect, "CX")
$height = DllStructGetData($rect, "CY")
Local $apos = WinGetPos($MainForm), $n1 = Floor($apos[2]/$width), $n2 = 0
For $i = 0 To UBound($ChildForm) - 1
If _API_IsIconic($ChildForm[$i]) Then $n2 += 1; 取最小化窗口数量
Next
ConsoleWrite($n1&@TAB&$n2&@TAB&$x&@TAB&$y&@CRLF)
If $n2 > $n1 Then;$n1是父窗体每行能容纳的最小化窗口数量
DllStructSetData($rect, "Y", $y - $iStatusHeight + $height)
Else
DllStructSetData($rect, "Y", $y - $iStatusHeight)
EndIf
$MoveForm = 0
EndIf
EndFunc ;==>WM_WINDOWPOSCHANGING
Func _CreateChildForm()
Local $j = 0
For $i = 0 To UBound($ChildForm) - 1
If Not IsHWnd($ChildForm[$i]) Then
$j = $i
ExitLoop
EndIf
Next
If $j < 1 Then
$j = $i
ReDim $ChildForm[$j + 1]
ReDim $ChildBtn[$j + 1]
EndIf
$ChildForm[$j] = GUICreate($j & "Child", 200, 100, 10 + $j * 10, 10 + $j * 15, BitOR($WS_CHILD, $WS_MINIMIZEBOX, $WS_MAXIMIZEBOX, $WS_CAPTION, $WS_SYSMENU), -1, $MainForm)
GUICtrlCreateLabel("我的句柄:" & $ChildForm[$j], 10, 10, 200, 60)
$ChildBtn[$j] = GUICtrlCreateButton("点我", 10, 70, 75, 25)
GUISetBkColor("0x" & Hex(Random(0, 255, 1), 2) & Hex(Random(0, 255, 1), 2) & Hex(Random(0, 255, 1), 2), $ChildForm[$j])
_WinAPI_SetParent($ChildForm[$j], $MainForm)
GUISetState(@SW_SHOW, $ChildForm[$j])
EndFunc ;==>_CreateChildForm
Func _CloseChildForm()
For $i = 0 To UBound($ChildForm) - 1
GUIDelete($ChildForm[$i])
$ChildForm[$i] = 0
Next
EndFunc ;==>_CloseChildForm
Func _API_IsIconic($hWnd)
Local $Ret = DllCall('user32.dll', 'int', 'IsIconic', 'long', $hWnd)
If @error Then
Return SetError(1, 0, 0)
EndIf
Return $Ret[0]
EndFunc
|