Animierter Button

  • Hi,
    ich möchte das, wenn ich ein Button mit einem Bild anklicke, das sich das Bild in ein anderes ändert und danach wieder zum Ausgangsbild wechselt.

    Hier ist mein bisheriger Code den ich mithilfe von Picture als Button animiert geschrieben habe:

    [autoit]


    #include<WindowsConstants.au3>
    #include<GUIConstantsEx.au3>
    #include<StaticConstants.au3>
    Global $pic = "button.bmp"

    [/autoit][autoit][/autoit][autoit]

    $gui = GUICreate("Form1", 257, 121, 192, 124)
    $btnPic = GUICtrlCreatePic($pic, 56, 32, 150, 50)
    GUISetState()

    [/autoit][autoit][/autoit][autoit][/autoit][autoit]

    While 1
    $msg = GUIGetMsg()
    Select
    Case $msg = $btnPic
    _AnimButton($gui, $btnPic)
    MsgBox(0, '', 'click')
    Case $msg = $GUI_EVENT_CLOSE
    Exit
    EndSelect
    WEnd

    [/autoit][autoit][/autoit][autoit]

    ;==================================================================================================
    ; Function Name: _AnimButton($IDgui, $IDbtn [, $delay=150])
    ; Description: animiert ein Pic, wie einen geklickten Button
    ; Parameter(s): $IDgui ID der GUI
    ; $IDbtn ID des Picture als Button
    ; optional $delay Verzögerung Zustand geklickt/nicht geklickt, Standard 150 ms
    ;==================================================================================================
    Func _AnimButton($IDgui, $IDbtn, $delay=150)
    Local $pos = ControlGetPos($IDgui, '', $IDbtn)
    Local $pWin = WinGetPos($IDgui)
    ControlMove($IDgui, '', $IDbtn, $pos[0], $pos[1]+1, $pos[2]-1, $pos[3]-1)
    Local $tmpGui = GUICreate('', $pos[2], $pos[3], $pWin[0]+$pos[0], $pWin[1]+$pos[1]+20, $WS_POPUP)
    WinSetTrans($tmpGui, '', 120)
    GUISetState(@SW_SHOW, $tmpGui)
    Sleep($delay)
    GUIDelete($tmpGui)
    ControlMove($IDgui, '', $IDbtn, $pos[0], $pos[1], $pos[2], $pos[3])
    EndFunc ;==> _AnimButton

    [/autoit][autoit][/autoit][autoit][/autoit]

    Also anstatt, das das eine Fenster transparent wird, soll ein neues Bild erstellt werden.

    Hoffe ihr wisst was ich meine ;)

    MfG

    Bladerunner85

    Einmal editiert, zuletzt von Bladerunner85 (16. Juli 2010 um 11:54)

  • meinst du so?

    [autoit]


    While 1
    $msg = GUIGetMsg()
    Select
    Case $msg = $btnPic
    GUICtrlSetImage ( $btnPic, "button2.bmp") ;ersatzbild
    MsgBox(0, '', 'click')
    GUICtrlSetImage ( $btnPic, "button.bmp") ;ursprungsbild
    Case $msg = $GUI_EVENT_CLOSE
    Exit
    EndSelect
    WEnd

    [/autoit]
  • Hallo Bladerunner85,

    hier ein Beispiel von BugFix auf 2 Bilder abgeändert:

    Spoiler anzeigen
    [autoit]

    #include<WindowsConstants.au3>
    #include<GUIConstantsEx.au3>
    #include<StaticConstants.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Global $pic = @SystemDir & '\oobe\images\nextover.jpg'
    Global $pic2 = @SystemDir & '\oobe\images\nextdown.jpg'

    [/autoit] [autoit][/autoit] [autoit]

    $gui = GUICreate("Test", Default, Default, -1, -1)
    $btnPic = GUICtrlCreatePic($pic, 30, 40, 24, 24)
    GUISetState()

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    While 1
    $msg = GUIGetMsg()
    Select
    Case $msg = $btnPic
    If _AnimButton($gui, $btnPic) Then MsgBox(0, '', 'click')
    Case $msg = $GUI_EVENT_CLOSE
    Exit
    EndSelect
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    ;==================================================================================================
    ; Function Name: _AnimButton($IDgui, $IDbtn [, $delay=150])
    ; Description: animiert ein Pic, wie einen geklickten Button
    ; Parameter(s): $IDgui ID der GUI
    ; $IDbtn ID des Picture als Button
    ;==================================================================================================
    Func _AnimButton($IDgui, $IDbtn)
    Local $pos = ControlGetPos($IDgui, '', $IDbtn)
    Local $pWin = WinGetPos(GUICtrlGetHandle($IDbtn))
    GUICtrlSetImage($IDbtn, $pic2)
    ControlMove($IDgui, '', $IDbtn, $pos[0], $pos[1] + 1, $pos[2] - 1, $pos[3] - 1)
    Local $tmpGui = GUICreate('', $pos[2], $pos[3], $pWin[0], $pWin[1], $WS_POPUP, $WS_EX_TOOLWINDOW)
    WinSetTrans($tmpGui, '', 120)
    GUISetState(@SW_SHOWNOACTIVATE, $tmpGui)
    $return = 1
    Do
    $x = GUIGetCursorInfo($IDgui)
    If $x[4] <> $IDbtn Then $return = 0
    Sleep(10)
    Until $x[2] = 0
    GUIDelete($tmpGui)
    GUICtrlSetImage($IDbtn, $pic)
    ControlMove($IDgui, '', $IDbtn, $pos[0], $pos[1], $pos[2], $pos[3])
    Return $return
    EndFunc ;==>_AnimButton

    [/autoit]

    Edit: andygo war schneller,

    mfg (Auto)Bert