找回密码
 加入
搜索
楼主: zz999

请教在别人的源码上修改的按钮动画效果

 火.. [复制链接]
 楼主| 发表于 2010-5-28 10:13:02 | 显示全部楼层
回复 15# C.L

真的很谢谢你的帮忙!

又一次发现个问题!
就是当我点了按钮1后  这时按钮是伸展,当再次点按钮1后    按钮开始收缩,
这时再点其他按钮,都不会伸展开来!


我帖上改后的源码!
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#include <ButtonConstants.au3>
#include <GuiButton.au3>
#include <GuiImageList.au3>
#include <EditConstants.au3>
#include <ListViewConstants.au3>
Dim $swap = False,$bstatus = ""
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("控件变化测试", 392, 265)
GUISetBkColor(0x000000)
$Button1 = GUICtrlCreateButton("显示图片", 8, 24, 40, 35)
$Button2 = GUICtrlCreateButton("显示图片", 8, 70, 40, 35)
$Button3 = GUICtrlCreateButton("显示编辑", 8, 115, 40, 35)
$Button4 = GUICtrlCreateButton("隐藏控件", 8, 161, 40, 35)
$Button5 = GUICtrlCreateButton("退出测试", 8, 207, 40, 35)
$Pic1 = GUICtrlCreatePic("E:\image\美女足球\01.jpg", 110, 24, 260, 220)
GUICtrlSetPos($Pic1, 110,24,260,20)
$Pic2 = GUICtrlCreatePic("E:\image\美女足球\02.jpg", 110, 24, 260, 220)
_ControlChange($Form1, $Pic2, 1, 100,5)
$Edit1 = GUICtrlCreateEdit("文本编辑框", 110, 24, 135, 217)
GUICtrlSetPos($Edit1, 110,24,1,217)
GUICtrlSetState($Pic1,$GUI_HIDE)
GUICtrlSetState($Pic2,$GUI_HIDE)
GUICtrlSetState($Edit1,$GUI_HIDE)
_GUICtrlButton_SetImageList($Button1, _Ico(165, True))
_GUICtrlButton_SetImageList($Button2, _Ico(166, True))
_GUICtrlButton_SetImageList($Button3, _Ico(134, True))
_GUICtrlButton_SetImageList($Button4, _Ico(146, True))
_GUICtrlButton_SetImageList($Button5, _Ico(217, True))
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
        $nMsg = GUIGetMsg()
        $mous = GUIGetCursorInfo($Form1)
        If $nMsg = $GUI_EVENT_CLOSE Then
                Exit        
        ElseIf $mous[4] = $Button1 Then                
                While $mous[4] = $Button1
                        If GUIGetMsg() = $Button1 Then 
                                If $bstatus <> "b1" Then $swap = Not $swap
        If Not $swap Then
                _ControlReset ()
        Else
                If $bstatus <> "b1" Then _ControlReset ()
                _ControlChange($Form1, $Button1, 0, 30, 3, 0, 0, 1, 0) 
                $bstatus = "b1"
        EndIf
        $swap = Not $swap
                                If GUICtrlGetState($Pic2)<>96 Then
                                        _ControlChange($Form1, $Pic2, 1, 100,5)
                                        GUICtrlSetState($Pic2,$GUI_HIDE)
                                EndIf
                                If GUICtrlGetState($Edit1)<>96 Then
                                        _ControlChange($Form1, $Edit1, 1, 135,5,0,0,1,0)
                                        GUICtrlSetState($Edit1,$GUI_HIDE)
                                EndIf
                                If GUICtrlGetState($Pic1)=96 Then
                                        GUICtrlSetState($Pic1,$GUI_SHOW)
                                        _ControlChange($Form1, $Pic1, 0, 100,5,0,0,0)
                                ElseIf GUICtrlGetState($Pic1)<>96 Then
                                        _ControlChange($Form1, $Pic1, 1, 100,5,0,0,0)
                                        GUICtrlSetState($Pic1,$GUI_HIDE)
                                EndIf
                        EndIf
                        $mous = GUIGetCursorInfo($Form1)
                WEnd
        ElseIf $mous[4] = $Button2 Then
                While $mous[4] = $Button2
                        If GUIGetMsg() = $Button2 Then 
                                If $bstatus <> "b2" Then $swap = Not $swap
        If Not $swap Then
                _ControlReset ()
        Else
                If $bstatus <> "b2" Then _ControlReset ()
                _ControlChange($Form1, $Button2, 0, 30, 3, 0, 0, 1, 0) 
                $bstatus = "b2"
        EndIf
        $swap = Not $swap
                                If GUICtrlGetState($Pic1)<>96 Then
                                        _ControlChange($Form1, $Pic1, 1, 100,5,0,0,0)
                                        GUICtrlSetState($Pic1,$GUI_HIDE)
                                EndIf
                                If GUICtrlGetState($Edit1)<>96 Then
                                        _ControlChange($Form1, $Edit1, 1, 135,5,0,0,1,0)
                                        GUICtrlSetState($Edit1,$GUI_HIDE)
                                EndIf
                                If GUICtrlGetState($Pic2)=96 Then
                                        GUICtrlSetState($Pic2,$GUI_SHOW)
                                        _ControlChange($Form1, $Pic2, 0, 100,5)
                                ElseIf GUICtrlGetState($Pic2)<>96 Then
                                        _ControlChange($Form1, $Pic2, 1, 100,5)
                                        GUICtrlSetState($Pic2,$GUI_HIDE)
                                EndIf                                
                        EndIf
                        $mous = GUIGetCursorInfo($Form1)
                WEnd
        ElseIf $mous[4] = $Button3 Then
                While $mous[4] = $Button3
                        If GUIGetMsg() = $Button3 Then 
                                If $bstatus <> "b3" Then $swap = Not $swap
        If Not $swap Then
                _ControlReset ()
        Else
                If $bstatus <> "b3" Then _ControlReset ()
                _ControlChange($Form1, $Button3, 0, 30, 3, 0, 0, 1, 0) 
                $bstatus = "b3"
        EndIf
        $swap = Not $swap
                                If GUICtrlGetState($Pic1)<>96 Then
                                        _ControlChange($Form1, $Pic1, 1, 100,5,0,0,0)
                                        GUICtrlSetState($Pic1,$GUI_HIDE)
                                EndIf
                                If GUICtrlGetState($Pic2)<>96 Then
                                        _ControlChange($Form1, $Pic2, 1, 100,5)
                                        GUICtrlSetState($Pic2,$GUI_HIDE)
                                EndIf
                                If GUICtrlGetState($Edit1)=96 Then
                                        GUICtrlSetState($Edit1,$GUI_SHOW)
                                        _ControlChange($Form1, $Edit1, 0, 135,5,0,0,1,0)
                                ElseIf GUICtrlGetState($Edit1)<>96 Then
                                        _ControlChange($Form1, $Edit1, 1, 135,5,0,0,1,0)
                                        GUICtrlSetState($Edit1,$GUI_HIDE)
                                EndIf
                        EndIf
                        $mous = GUIGetCursorInfo($Form1)
                WEnd
        ElseIf $mous[4] = $Button4 Then
                While $mous[4] = $Button4
                        If GUIGetMsg() = $Button4 Then 
                                If $bstatus <> "b4" Then $swap = Not $swap
        If Not $swap Then
                _ControlReset ()
        Else
                If $bstatus <> "b4" Then _ControlReset ()
                _ControlChange($Form1, $Button4, 0, 30, 3, 0, 0, 1, 0) 
                $bstatus = "b4"
        EndIf
        $swap = Not $swap
                                If GUICtrlGetState($Pic1)<>96 Then
                                        GUICtrlSetState($Pic1,$GUI_HIDE)
                                        _ControlChange($Form1, $Pic1, 1, 100,5,0,0,0)                                        
                                EndIf
                                If GUICtrlGetState($Pic2)<>96 Then
                                        GUICtrlSetState($Pic2,$GUI_HIDE)
                                        _ControlChange($Form1, $Pic2, 1, 100,5)                                        
                                EndIf
                                If GUICtrlGetState($Edit1)<>96 Then
                                        GUICtrlSetState($Edit1,$GUI_HIDE)
                                        _ControlChange($Form1, $Edit1, 1, 135,5,0,0,1,0)
                                EndIf
                        EndIf
                        $mous = GUIGetCursorInfo($Form1)
                WEnd
        ElseIf $mous[4] = $Button5 Then        
                While $mous[4] = $Button5
                        If GUIGetMsg() = $Button5 Then 
                        If $bstatus <> "b5" Then $swap = Not $swap
        If Not $swap Then
                _ControlReset ()
        Else
                If $bstatus <> "b5" Then _ControlReset ()
                _ControlChange($Form1, $Button5, 0, 30, 3, 0, 0, 1, 0) 
                $bstatus = "b5"
        EndIf
        $swap = Not $swap
                Exit
                EndIf
                        $mous = GUIGetCursorInfo($Form1)
                WEnd
        EndIf
WEnd

Func _Ico($nIconID = 0, $fLarge = False, $sFile = "shell32.dll")
        Local $iSize = 16
        If $fLarge Then $iSize = 32

        Local $hImagetem = _GUIImageList_Create($iSize, $iSize, 5, 3)
        If StringUpper(StringMid($sFile, StringLen($sFile) - 2)) = "BMP" Then
                _GUIImageList_AddBitmap($hImagetem, $sFile)
        Else
                _GUIImageList_AddIcon($hImagetem, $sFile, $nIconID, $fLarge)
        EndIf
        Return $hImagetem
EndFunc   ;==>_Ico

Func _ControlChange($FormID, $controlID, $iStup = 0, $iMax = 10, $iStep = 2, $iXs = 1, $iYs = 1, $iWs = 1, $iHs = 1)
;~         控件变化动画效果
;~         _ControlChange (窗口标题/ID, 控件ID, 变化设置 0变大否则变小, 变化大小, 变化速度, X坐标变化, Y坐标变化,宽度变化,高度变化)
        $iPos = ControlGetPos($FormID, "", $controlID)
        $iX = $iPos[0]
        $iY = $iPos[1]
        $iW = $iPos[2]
        $iH = $iPos[3]
        If $iStup = 0 Then
                $iS1 = 1
                $iS2 = 1
        Else
                $iS1 = -1
                $iS2 = -1
        EndIf
        Dim $iXt = $iX, $iYt = $iY, $iWt = $iW, $iHt = $iH
        For $i = 1 To $iMax Step $iStep
                If $iXs = 1 Then $iXt = Execute($iX - $iS1 * $i)
                If $iYs = 1 Then $iYt = Execute($iY - $iS1 * $i)
                If $iWs = 1 Then $iWt = Execute($iW + $iS2 * 2 * $i)
                If $iHs = 1 Then $iHt = Execute($iH + $iS2 * 2 * $i)
                GUICtrlSetPos($controlID, $iXt, $iYt, $iWt, $iHt)
                Sleep(1)
        Next
EndFunc   ;==>_ControlChange

Func _ControlReset ()
        GUICtrlSetPos($Button1,8,24,40,35)
        GUICtrlSetPos($Button2,8,70,40,35)
        GUICtrlSetPos($Button3,8,115,40,35)
        GUICtrlSetPos($Button4,8,161,40,35)
        GUICtrlSetPos($Button5,8,207,40,35)
EndFunc
发表于 2010-5-29 00:35:16 | 显示全部楼层
哦,这个开关用一个开关控制5个按钮,绕得有点晕,我再改一下,这次应该没问题了
方便你测试,这次贴上所有代码,你再测试看看,是不是还会出现什么问题。
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#include <ButtonConstants.au3>
#include <GuiButton.au3>
#include <GuiImageList.au3>
#include <EditConstants.au3>
#include <ListViewConstants.au3>
Dim $swap = False, $bstatus = ""
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("控件变化测试", 392, 265)
GUISetBkColor(0x000000)
$Button1 = GUICtrlCreateButton("显示图片", 8, 24, 40, 35)
$Button2 = GUICtrlCreateButton("显示图片", 8, 70, 40, 35)
$Button3 = GUICtrlCreateButton("显示编辑", 8, 115, 40, 35)
$Button4 = GUICtrlCreateButton("隐藏控件", 8, 161, 40, 35)
$Button5 = GUICtrlCreateButton("退出测试", 8, 207, 40, 35)
$Pic1 = GUICtrlCreatePic("E:\image\美女足球\01.jpg", 110, 24, 260, 220)
GUICtrlSetPos($Pic1, 110, 24, 260, 20)
$Pic2 = GUICtrlCreatePic("E:\image\美女足球\02.jpg", 110, 24, 260, 220)
_ControlChange($Form1, $Pic2, 1, 100, 5)
$Edit1 = GUICtrlCreateEdit("文本编辑框", 110, 24, 135, 217)
GUICtrlSetPos($Edit1, 110, 24, 1, 217)
GUICtrlSetState($Pic1, $GUI_HIDE)
GUICtrlSetState($Pic2, $GUI_HIDE)
GUICtrlSetState($Edit1, $GUI_HIDE)
_GUICtrlButton_SetImageList($Button1, _Ico(165, True))
_GUICtrlButton_SetImageList($Button2, _Ico(166, True))
_GUICtrlButton_SetImageList($Button3, _Ico(134, True))
_GUICtrlButton_SetImageList($Button4, _Ico(146, True))
_GUICtrlButton_SetImageList($Button5, _Ico(217, True))
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
While 1
        $nMsg = GUIGetMsg()
        $mous = GUIGetCursorInfo($Form1)
        If $nMsg = $GUI_EVENT_CLOSE Then
                Exit        
        ElseIf $mous[4] = $Button1 Then                
                While $mous[4] = $Button1
                        If GUIGetMsg() = $Button1 Then 
                                If $bstatus == "b1" And Not $swap Then
                                        _ControlReset ()
                                        $swap = Not $swap
                                Else
                                        _ControlReset ()
                                        _ControlChange($Form1, $Button1, 0, 30, 3, 0, 0, 1, 0) 
                                        $bstatus = "b1"
                                        If $swap Then $swap = Not $swap
                                EndIf
                                If GUICtrlGetState($Pic2)<>96 Then
                                        _ControlChange($Form1, $Pic2, 1, 100,5)
                                        GUICtrlSetState($Pic2,$GUI_HIDE)
                                EndIf
                                If GUICtrlGetState($Edit1)<>96 Then
                                        _ControlChange($Form1, $Edit1, 1, 135,5,0,0,1,0)
                                        GUICtrlSetState($Edit1,$GUI_HIDE)
                                EndIf
                                If GUICtrlGetState($Pic1)=96 Then
                                        GUICtrlSetState($Pic1,$GUI_SHOW)
                                        _ControlChange($Form1, $Pic1, 0, 100,5,0,0,0)
                                ElseIf GUICtrlGetState($Pic1)<>96 Then
                                        _ControlChange($Form1, $Pic1, 1, 100,5,0,0,0)
                                        GUICtrlSetState($Pic1,$GUI_HIDE)
                                EndIf
                        EndIf
                        $mous = GUIGetCursorInfo($Form1)
                WEnd
        ElseIf $mous[4] = $Button2 Then                
                While $mous[4] = $Button2
                        If GUIGetMsg() = $Button2 Then 
                                If $bstatus == "b2" And Not $swap Then
                                        _ControlReset ()
                                        $swap = Not $swap
                                Else
                                        _ControlReset ()
                                        _ControlChange($Form1, $Button2, 0, 30, 3, 0, 0, 1, 0) 
                                        $bstatus = "b2"
                                        If $swap Then $swap = Not $swap
                                EndIf
                                If GUICtrlGetState($Pic1)<>96 Then
                                        _ControlChange($Form1, $Pic1, 1, 100,5,0,0,0)
                                        GUICtrlSetState($Pic1,$GUI_HIDE)
                                EndIf
                                If GUICtrlGetState($Edit1)<>96 Then
                                        _ControlChange($Form1, $Edit1, 1, 135,5,0,0,1,0)
                                        GUICtrlSetState($Edit1,$GUI_HIDE)
                                EndIf
                                If GUICtrlGetState($Pic2)=96 Then
                                        GUICtrlSetState($Pic2,$GUI_SHOW)
                                        _ControlChange($Form1, $Pic2, 0, 100,5)
                                ElseIf GUICtrlGetState($Pic2)<>96 Then
                                        _ControlChange($Form1, $Pic2, 1, 100,5)
                                        GUICtrlSetState($Pic2,$GUI_HIDE)
                                EndIf
                        EndIf
                        $mous = GUIGetCursorInfo($Form1)
                WEnd
        ElseIf $mous[4] = $Button3 Then                
                While $mous[4] = $Button3
                        If GUIGetMsg() = $Button3 Then 
                                If $bstatus == "b3" And Not $swap Then
                                        _ControlReset ()
                                        $swap = Not $swap
                                Else
                                        _ControlReset ()
                                        _ControlChange($Form1, $Button3, 0, 30, 3, 0, 0, 1, 0) 
                                        $bstatus = "b3"
                                        If $swap Then $swap = Not $swap
                                EndIf
                                If GUICtrlGetState($Pic1)<>96 Then
                                        _ControlChange($Form1, $Pic1, 1, 100,5,0,0,0)
                                        GUICtrlSetState($Pic1,$GUI_HIDE)
                                EndIf
                                If GUICtrlGetState($Pic2)<>96 Then
                                        _ControlChange($Form1, $Pic2, 1, 100,5)
                                        GUICtrlSetState($Pic2,$GUI_HIDE)
                                EndIf
                                If GUICtrlGetState($Edit1)=96 Then
                                        GUICtrlSetState($Edit1,$GUI_SHOW)
                                        _ControlChange($Form1, $Edit1, 0, 135,5,0,0,1,0)
                                ElseIf GUICtrlGetState($Edit1)<>96 Then
                                        _ControlChange($Form1, $Edit1, 1, 135,5,0,0,1,0)
                                        GUICtrlSetState($Edit1,$GUI_HIDE)
                                EndIf
                        EndIf
                        $mous = GUIGetCursorInfo($Form1)
                WEnd
        ElseIf $mous[4] = $Button4 Then        
                While $mous[4] = $Button4
                        If GUIGetMsg() = $Button4 Then 
                                If $bstatus == "b4" And Not $swap Then
                                        _ControlReset ()
                                        $swap = Not $swap
                                Else
                                        _ControlReset ()
                                        _ControlChange($Form1, $Button4, 0, 30, 3, 0, 0, 1, 0) 
                                        $bstatus = "b4"
                                        If $swap Then $swap = Not $swap
                                EndIf
                                If GUICtrlGetState($Pic1)<>96 Then
                                        GUICtrlSetState($Pic1,$GUI_HIDE)
                                        _ControlChange($Form1, $Pic1, 1, 100,5,0,0,0)                                        
                                EndIf
                                If GUICtrlGetState($Pic2)<>96 Then
                                        GUICtrlSetState($Pic2,$GUI_HIDE)
                                        _ControlChange($Form1, $Pic2, 1, 100,5)                                        
                                EndIf
                                If GUICtrlGetState($Edit1)<>96 Then
                                        GUICtrlSetState($Edit1,$GUI_HIDE)
                                        _ControlChange($Form1, $Edit1, 1, 135,5,0,0,1,0)
                                EndIf
                        EndIf
                        $mous = GUIGetCursorInfo($Form1)
                WEnd
        ElseIf $mous[4] = $Button5 Then
                While $mous[4] = $Button5
                        If GUIGetMsg() = $Button5 Then
                                If $bstatus == "b5" And Not $swap Then
                                        _ControlReset ()
                                        $swap = Not $swap
                                Else
                                        _ControlReset ()
                                        _ControlChange($Form1, $Button5, 0, 30, 3, 0, 0, 1, 0) 
                                        $bstatus = "b5"
                                        If $swap Then $swap = Not $swap
                                EndIf
                                Exit
                        EndIf
                        $mous = GUIGetCursorInfo($Form1)
                WEnd
        EndIf
WEnd

Func _Ico($nIconID = 0, $fLarge = False, $sFile = "shell32.dll")
        Local $iSize = 16
        If $fLarge Then $iSize = 32
        Local $hImagetem = _GUIImageList_Create($iSize, $iSize, 5, 3)
        If StringUpper(StringMid($sFile, StringLen($sFile) - 2)) = "BMP" Then
                _GUIImageList_AddBitmap($hImagetem, $sFile)
        Else
                _GUIImageList_AddIcon($hImagetem, $sFile, $nIconID, $fLarge)
        EndIf
        Return $hImagetem
EndFunc   ;==>_Ico

Func _ControlChange($FormID, $controlID, $iStup = 0, $iMax = 10, $iStep = 2, $iXs = 1, $iYs = 1, $iWs = 1, $iHs = 1)
;~         控件变化动画效果
;~         _ControlChange (窗口标题/ID, 控件ID, 变化设置 0变大否则变小, 变化大小, 变化速度, X坐标变化, Y坐标变化,宽度变化,高度变化)
        $iPos = ControlGetPos($FormID, "", $controlID)
        $iX = $iPos[0]
        $iY = $iPos[1]
        $iW = $iPos[2]
        $iH = $iPos[3]
        If $iStup = 0 Then
                $iS1 = 1
                $iS2 = 1
        Else
                $iS1 = -1
                $iS2 = -1
        EndIf
        Dim $iXt = $iX, $iYt = $iY, $iWt = $iW, $iHt = $iH
        For $i = 1 To $iMax Step $iStep
                If $iXs = 1 Then $iXt = Execute($iX - $iS1 * $i)
                If $iYs = 1 Then $iYt = Execute($iY - $iS1 * $i)
                If $iWs = 1 Then $iWt = Execute($iW + $iS2 * 2 * $i)
                If $iHs = 1 Then $iHt = Execute($iH + $iS2 * 2 * $i)
                GUICtrlSetPos($controlID, $iXt, $iYt, $iWt, $iHt)
                Sleep(1)
        Next
EndFunc   ;==>_ControlChange

Func _ControlReset()
        GUICtrlSetPos($Button1, 8, 24, 40, 35)
        GUICtrlSetPos($Button2, 8, 70, 40, 35)
        GUICtrlSetPos($Button3, 8, 115, 40, 35)
        GUICtrlSetPos($Button4, 8, 161, 40, 35)
        GUICtrlSetPos($Button5, 8, 207, 40, 35)
EndFunc   ;==>_ControlReset

评分

参与人数 1金钱 +30 贡献 +5 收起 理由
zz999 + 30 + 5 谢谢!

查看全部评分

 楼主| 发表于 2010-5-29 01:42:13 | 显示全部楼层
回复 17# C.L


夜猫子一个,哈哈   谢谢你!
结贴了!
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-6-2 05:33 , Processed in 0.074230 second(s), 18 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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