找回密码
 加入
搜索
查看: 2438|回复: 3

[GUI管理] [已解决] 在OnEvent模式下 窗口收缩问题。

[复制链接]
发表于 2012-5-14 22:34:05 | 显示全部楼层 |阅读模式
本帖最后由 非典男人 于 2012-5-14 22:40 编辑

不启用OnEvent 模式 展开窗口功能正常,启动OnEvent 模式后 就没办法展开收缩,  有了解的希望帮忙处理下,感谢。
问题解决  修改 _GUIExtender_Section_Action(2, "<", ">", 70, 20, 15, 15) 成 _GUIExtender_Section_Action(2, "<", ">", 70, 20, 15, 15,0,1) ;修改此处就解决掉了、

GUIExtender.au3 文件 第二个代码

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIExtender.au3>
Opt("GUIOnEventMode", 1)    ;注释掉这个之后就正常了。
Global $nMsg 
$hGUI = GUICreate("Form1", 570, 360)
GUISetOnEvent($GUI_EVENT_CLOSE, "GuiClose")
_GUIExtender_Init($hGUI, 1)
_GUIExtender_Section_Start(0, 400)
GUICtrlCreateGroup("1 - 默认",  2, -6, 300, 360) 
_GUIExtender_Section_Action(2, "<", ">", 70, 20, 15, 15)  
;_GUIExtender_Section_Action(2, "<", ">", 70, 20, 15, 15,0,1) ;修改此处就解决掉了、
_GUIExtender_Section_End()
GUICtrlCreateGroup("", -99, -99, 1, 1)

_GUIExtender_Section_Start(400, 266)
GUICtrlCreateGroup("2 - 扩展的", 312, -6, 254, 360)
_GUIExtender_Section_End()

GUICtrlCreateGroup("", -99, -99, 1, 1)
_GUIExtender_Section_Extend(2, False)
GUISetState()
#EndRegion ### END Koda GUI section ###
While 1
        $iMsg = GUIGetMsg()
        Switch $iMsg
                Case $GUI_EVENT_CLOSE
                        Exit
        EndSwitch
        _GUIExtender_Action($iMsg) ; Check for click on Action control
WEnd

Func GuiClose()
Exit
EndFunc



下面是  GUIExtender.au3  文件 代码

#include-once

#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
Global $aSection_Data[1][9] = [[0, 0, 1, 0, "", 9999]]
Func _GUIExtender_Init($hWnd, $iOrient = 0)

        If Not IsHWnd($hWnd) Then
                Return SetError(1, 0, 0)
        Else
                $aSection_Data[0][3] = $hWnd
                $aSection_Data[0][1] = $iOrient
                Opt("GUIResizeMode", 0x0322)
                GUISetOnEvent(-5, "_GUIExtender_Restore") 
                Return 1
        EndIf

EndFunc 

Func _GUIExtender_Section_Start($iSection_Coord, $iSection_Size)

        If $aSection_Data[0][0] > 1 Then
                If $aSection_Data[$aSection_Data[0][0] - 1][0] + $aSection_Data[$aSection_Data[0][0] - 1][1] > $iSection_Coord Then Return SetError(1, 0, 0)
        EndIf
        $aSection_Data[0][0] += 1
        If UBound($aSection_Data) < $aSection_Data[0][0] + 1 Then
                ReDim $aSection_Data[$aSection_Data[0][0] + 1][9]
        EndIf
        $aSection_Data[$aSection_Data[0][0]][0] = $iSection_Coord
        $aSection_Data[$aSection_Data[0][0]][1] = $iSection_Size
        If $aSection_Data[$aSection_Data[0][0]][2] = "" Then $aSection_Data[$aSection_Data[0][0]][2] = 2
        If $aSection_Data[0][1] Then 
                $aSection_Data[$aSection_Data[0][0]][3] = GUICtrlCreateLabel("", $iSection_Coord, 0, 0, 0)
        Else
                $aSection_Data[$aSection_Data[0][0]][3] = GUICtrlCreateLabel("", 0, $iSection_Coord, 0, 0)
        EndIf
        GUICtrlSetState(-1, 128)
        If $aSection_Data[$aSection_Data[0][0]][5] = "" Then $aSection_Data[$aSection_Data[0][0]][5] = 9999
        Return $aSection_Data[0][0]

EndFunc  
Func _GUIExtender_Section_End()
        $aSection_Data[$aSection_Data[0][0]][4] = GUICtrlCreateDummy() - 1

EndFunc

Func _GUIExtender_Section_Action($iSection, $sText_Extended = "", $sText_Retracted = "", $iX = 0, $iY = 0, $iW = 1, $iH = 1, $iType = 0, $iEventMode = 0)
        If $iSection > 1 And UBound($aSection_Data) < $iSection + 1 Then
                ReDim $aSection_Data[$iSection + 1][9]
        EndIf
        $aSection_Data[$iSection][2] = 1
        Local $iDef_Arrows = 0
        If $sText_Extended = "" And $sText_Retracted = "" Then
                $iDef_Arrows = 1
                If $aSection_Data[0][1] Then 
                        $sText_Extended = 3
                        $sText_Retracted = 4
                Else
                        $sText_Extended = 5
                        $sText_Retracted = 6
                EndIf
        EndIf
        Switch $iType
                Case 0
                        $aSection_Data[$iSection][5] = GUICtrlCreateButton($sText_Extended, $iX, $iY, $iW, $iH)
                Case Else
                        $aSection_Data[$iSection][5] = GUICtrlCreateCheckbox($sText_Extended, $iX, $iY, $iW, $iH, 0x1000) ; $BS_PUSHLIKE
                        GUICtrlSetState(-1, 1) 
        EndSwitch
        If $aSection_Data[$iSection][5] = 0 Then Return SetError(2, 0, 0)
        If $iDef_Arrows Then GUICtrlSetFont($aSection_Data[$iSection][5], 10, 400, 0, "Webdings")
        If $iEventMode Then GUICtrlSetOnEvent($aSection_Data[$iSection][5], "_GUIExtender_Section_Action_Event")
        $aSection_Data[$iSection][6] = $sText_Extended
        $aSection_Data[$iSection][7] = $sText_Retracted
        $aSection_Data[$iSection][8] = $iType

        Return 1

EndFunc 
Func _GUIExtender_Action($iMsg)

        If $iMsg = $GUI_EVENT_RESTORE Then _GUIExtender_Restore()
        For $i = 0 To $aSection_Data[0][0]
                If $iMsg = $aSection_Data[$i][5] Then
                        Switch $aSection_Data[$i][2]
                                Case 0
                                        _GUIExtender_Section_Extend($i, True)
                                Case Else
                                        _GUIExtender_Section_Extend($i, False)
                        EndSwitch
                        ExitLoop
                EndIf
        Next

EndFunc 

Func _GUIExtender_Restore()

        GUISetState(@SW_HIDE, $aSection_Data[0][3])
        For $i = UBound($aSection_Data) - 1 To 1 Step -1
                If $aSection_Data[$i][2] <> 2 Then
                        Switch $aSection_Data[$i][2]
                                Case 0
                                        _GUIExtender_Section_Extend($i)
                                        _GUIExtender_Section_Extend($i, False)
                                Case 1
                                        _GUIExtender_Section_Extend($i, False)
                                        _GUIExtender_Section_Extend($i)
                        EndSwitch
                        ExitLoop
                EndIf
        Next
        GUISetState(@SW_SHOW, $aSection_Data[0][3])

EndFunc  
Func _GUIExtender_Section_Extend($iSection, $fExtend = True)

        Local $aPos
        If $iSection = 0 Then
                _GUIExtender_Section_All_Extend($fExtend)
                Return 1
        EndIf

        If $iSection > UBound($aSection_Data) - 1 Then Return SetError(1, 1, 0)
        If $aSection_Data[$iSection][1] = "" Then Return SetError(1, 2, 0)
        If ($aSection_Data[$iSection][2] = 1 And $fExtend = True) Or ($aSection_Data[$iSection][2] = 0 And $fExtend = False) Then Return SetError(2, 0, 0)
        Local $aGUIPos = WinGetPos($aSection_Data[0][3])
        Local $iGUI_Fixed = $aGUIPos[2]
        Local $iGUI_Adjust = $aGUIPos[3]
        If $aSection_Data[0][1] Then 
                $iGUI_Fixed = $aGUIPos[3]
                $iGUI_Adjust = $aGUIPos[2]
        EndIf

        If $fExtend Then
                GUICtrlSetData($aSection_Data[$iSection][5], $aSection_Data[$iSection][6])
                If $aSection_Data[$iSection][8] = 1 Then GUICtrlSetState($aSection_Data[$iSection][5], 1)
                $aSection_Data[$iSection][2] = 1
                $iGUI_Adjust += $aSection_Data[$iSection][1]
        Else
                GUICtrlSetData($aSection_Data[$iSection][5], $aSection_Data[$iSection][7])
                If $aSection_Data[$iSection][8] = 1 Then GUICtrlSetState($aSection_Data[$iSection][5], 4)
                $aSection_Data[$iSection][2] = 0
                $iGUI_Adjust -= $aSection_Data[$iSection][1]
        EndIf

        For $i = $aSection_Data[1][3] To $aSection_Data[$aSection_Data[0][0]][4]
                GUICtrlSetState($i, 32) 
        Next

        If $aSection_Data[0][1] Then 
                WinMove($aSection_Data[0][3], "", Default, Default, $iGUI_Adjust, $iGUI_Fixed)
        Else
                WinMove($aSection_Data[0][3], "", Default, Default, $iGUI_Fixed, $iGUI_Adjust)
        EndIf

        Local $iNext_Coord = $aSection_Data[1][0]
        For $i = 1 To $aSection_Data[0][0]
                If $aSection_Data[$i][2] > 0 Then
                        $aPos = ControlGetPos($aSection_Data[0][3], "", $aSection_Data[$i][3])
                        If $aSection_Data[0][1] Then 
                                Local $iAdjust_X = $aPos[0] - $iNext_Coord
                                Local $iAdjust_Y = 0
                                If $aPos[1] > $iGUI_Fixed Then $iAdjust_Y = $iGUI_Fixed
                        Else
                                $iAdjust_Y = $aPos[1] - $iNext_Coord
                                $iAdjust_X = 0
                                If $aPos[0] > $iGUI_Fixed Then $iAdjust_X = $iGUI_Fixed
                        EndIf
                        For $j = $aSection_Data[$i][3] To $aSection_Data[$i][4]
                                $aPos = ControlGetPos($aSection_Data[0][3], "", $j)
                                ControlMove($aSection_Data[0][3], "", $j, $aPos[0] - $iAdjust_X, $aPos[1] - $iAdjust_Y)
                                GUICtrlSetState($j, 16)
                        Next
                        $iNext_Coord += $aSection_Data[$i][1]
                Else
                        $aPos = ControlGetPos($aSection_Data[0][3], "", $aSection_Data[$i][3])
                        If $aSection_Data[0][1] Then 
                                If $aPos[1] < $iGUI_Fixed Then
                                        For $j = $aSection_Data[$i][3] To $aSection_Data[$i][4]
                                                ControlMove($aSection_Data[0][3], "", $j, $aPos[0], $aPos[1] + $iGUI_Fixed)
                                        Next
                                EndIf
                        Else
                                If $aPos[0] < $iGUI_Fixed Then
                                        For $j = $aSection_Data[$i][3] To $aSection_Data[$i][4]
                                                ControlMove($aSection_Data[0][3], "", $j, $aPos[0] + $iGUI_Fixed, $aPos[1])
                                        Next
                                EndIf
                        EndIf
                EndIf
        Next
        If $aSection_Data[0][5] <> 9999 Then
                Local $iAll_State = 0
                For $i = 1 To $aSection_Data[0][0]
                        If $aSection_Data[$i][2] = 1 Then
                                $iAll_State = 1
                                ExitLoop
                        EndIf
                Next
                Switch $iAll_State
                        Case 0
                                $aSection_Data[0][2] = 0
                                GUICtrlSetData($aSection_Data[0][5], $aSection_Data[0][7])
                                If $aSection_Data[0][8] = 1 Then GUICtrlSetState($aSection_Data[0][5], 4) 
                        Case Else
                                $aSection_Data[0][2] = 1
                                GUICtrlSetData($aSection_Data[0][5], $aSection_Data[0][6])
                                If $aSection_Data[0][8] = 1 Then GUICtrlSetState($aSection_Data[0][5], 1) 
                EndSwitch
        EndIf

        Return 1

EndFunc 
Func _GUIExtender_Section_State($iSection)

        Return $aSection_Data[$iSection][2]

EndFunc  
Func _GUIExtender_Section_All_Extend($fExtend = True)
        Local $iState = 0
        If $fExtend Then $iState = 1

        For $i = 1 To $aSection_Data[0][0]
                If $aSection_Data[$i][2] <> 2 And $aSection_Data[$i][2] = Not ($iState) Then
                        _GUIExtender_Section_Extend($i, $fExtend)
                        $aSection_Data[$i][2] = $iState
                        Switch $fExtend
                                Case True
                                        GUICtrlSetData($aSection_Data[$i][5], $aSection_Data[$i][6])
                                        If $aSection_Data[$i][8] = 1 Then GUICtrlSetState($aSection_Data[$i][5], 1) 
                                Case False
                                        GUICtrlSetData($aSection_Data[$i][5], $aSection_Data[$i][7])
                                        If $aSection_Data[$i][8] = 1 Then GUICtrlSetState($aSection_Data[$i][5], 4) 
                        EndSwitch
                EndIf
        Next

EndFunc 
Func _GUIExtender_Section_Action_Event()

        _GUIExtender_Action(@GUI_CtrlId)

EndFunc
发表于 2012-5-14 22:55:51 | 显示全部楼层
楼主好人 , 收藏备用
发表于 2012-5-25 02:36:14 | 显示全部楼层
同上  楼主好人 , 收藏备用
发表于 2013-4-9 14:54:52 | 显示全部楼层
今天才看到,想要了好久
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-6-2 07:10 , Processed in 0.075440 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表