Mouse over immer noch Probleme

  • Hallo,

    ich bin wirklich fast am verzweifeln mit meinen MouseOver-Problemen.

    Es klappt einfach nicht zufriedenstellend.
    Hier mal wieder Code....

    Zuerst die Funktion:

    [autoit]


    $hover = 0
    Func _mover($control, $bild1, $bild2)

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

    $mpos = GUIGetCursorInfo($Gui_Main)
    If (IsArray($mpos)) Then
    If ($mpos[4] = $control) Then
    ;MsgBox(4,"","")
    GUICtrlSetImage($control, $bild2)
    $hover = 1
    Elseif ($mpos[4] <> $control and $hover = 1) Then
    GUICtrlSetImage($control, $bild1)
    $hover = 0
    EndIf
    EndIf

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

    EndFunc

    [/autoit]

    dann das Script

    [autoit]


    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #include <ButtonConstants.au3>
    #include "_mover.au3"
    #Include <Array.au3>

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

    $Gui_Main = GUICreate("Gui_Main", 405, 400, 302, 218)
    $IconKat1Off = GUICtrlCreateIcon("icon01.ico", -1, 48, 108, 219, 52)
    $IconKat2Off = GUICtrlCreateIcon("icon01.ico", -1, 48, 164, 219, 52)
    $IconKat3Off = GUICtrlCreateIcon("icon01.ico", -1, 48, 220, 219, 52)
    $IconKat4Off = GUICtrlCreateIcon("icon01.ico", -1, 48, 280, 219, 52)
    $IconEndeoff = GUICtrlCreateIcon("iconEndeoff.ico", -1, 572, 36, 48, 48)
    GUISetState(@SW_SHOW)

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

    $Bild1 = @ScriptDir & "\Icon01.ico"
    $Bild2 = @ScriptDir & "\icon02.ico"
    $Bild3 = @ScriptDir & "\icon03.ico"

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

    While 1
    $nMsg = GUIGetMsg()

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

    _mover($IconKat1Off, $Bild1,$Bild2)
    _mover($IconKat2Off, $Bild1,$Bild2)
    _mover($IconKat3Off, $Bild1,$Bild2)
    _mover($IconKat4Off, $Bild1,$Bild2)

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

    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit

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

    EndSwitch
    WEnd

    [/autoit]

    die Buttons werden nicht korrekt ausgeschaltet,
    zittern...

    Sieht so aus:
    [attach=12070,'none','2']


    Liebe Grüße
    Ilse ;)

    Einmal editiert, zuletzt von Ilse (15. Dezember 2010 um 16:07)

  • Du deklarierst die Variable $hover aber nutzt sie nicht? Du merkst doch hoffentlich, dass das nicht gerade sinnvoll ist...
    Edit: Sry, hab nich gesehen, dass du die Variable doch nutzt. Aber einmal benutzt du die Variable nicht ;)
    Edit2: Hier mal ein kleines Beispiel:

    Spoiler anzeigen
    [autoit]

    $hGUI = GUICreate("MouseOverSetImage Beispiel", 514, 153, 192, 124)
    $pic1 = GUICtrlCreatePic("p1.jpg", 0, 0, 257, 153)
    GUISetState()
    While True
    Switch GUIGetMsg()
    Case -3
    Exit
    EndSwitch
    mouseOverSetImage($pic1, "p1.jpg", "p2.jpg")
    WEnd
    Func mouseOverSetImage($ctrlID, $pic1, $pic2)
    Local Static $hover=false
    $mPos=GUIGetCursorInfo()
    If IsArray($mPos) Then
    If $mPos[4]=$ctrlID And $hover=false Then
    GUICtrlSetImage($ctrlID, $pic2)
    $hover=True
    ElseIf $mPos[4]<>$ctrlID And $hover Then
    GUICtrlSetImage($ctrlID, $pic1)
    $hover=False
    EndIf
    EndIf
    EndFunc

    [/autoit]

    3 Mal editiert, zuletzt von Ineluki (14. Dezember 2010 um 14:32)

  • Hallo Ineluki,

    hm...so ganz versteh ich's noch nicht!
    D.h.
    mouseOverSetImage($pic1, "p1.jpg", "p2.jpg")

    p1.jpg, p2.jpg sind nicht im Script
    Ich meine:
    $Bild1 = @ScriptDir & "\Icon01.ico"
    kann ich mir sparen?

    Ich habe ja mehrere icons.
    Wie muß ich die Funktion noch ändern?


    huh...
    Grüße
    Ilse ;)

    • Offizieller Beitrag
  • Wie wäre es damit?

    Spoiler anzeigen
    [autoit]

    #include <GUIConstantsEx.au3>

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

    ; Ein paar Konstanten
    Global Const $STM_SETICON = 0x0170
    Global Const $STM_GETICON = 0x0171
    Global Const $STM_SETIMAGE = 0x0172
    Global Const $STM_GETIMAGE = 0x0173

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

    Global Const $IMAGE_BITMAP = 0
    Global Const $IMAGE_ICON = 1
    Global Const $IMAGE_CURSOR = 2

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

    ; Icons in Dummy GUI laden und auslesen
    GuiCreate("Dummy")
    GUICtrlCreateIcon(@WindowsDir & "\cursors\dinosaur.ani", -1, 0, 0, 32, 32)
    $hIcon1 = GUICtrlSendMsg(-1, $STM_GETICON, 0, 0)
    GUICtrlCreateIcon(@WindowsDir & "\cursors\horse.ani", -1, 0, 40, 32, 32)
    $hIcon2 = GUICtrlSendMsg(-1, $STM_GETICON, 0, 0)

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

    ; Main GUI
    $Gui_Main = GUICreate("Gui_Main", 405, 400, 302, 218)
    $IconKat1Off = GUICtrlCreateIcon("", -1, 48, 108, 32, 32)
    GUICtrlSendMsg(-1, $STM_SETICON, $hIcon1, 0)
    $IconKat2Off = GUICtrlCreateIcon("", -1, 48, 164, 32, 32)
    GUICtrlSendMsg(-1, $STM_SETICON, $hIcon1, 0)
    $IconKat3Off = GUICtrlCreateIcon("", -1, 48, 220, 32, 32)
    GUICtrlSendMsg(-1, $STM_SETICON, $hIcon1, 0)
    $IconKat4Off = GUICtrlCreateIcon("", -1, 48, 280, 32, 32)
    GUICtrlSendMsg(-1, $STM_SETICON, $hIcon1, 0)

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

    ; Array für Hovercontrols aufbauen [ControlID, Normales Bild, Mouseover Bild]
    Dim $aHover[4][3] = [ _
    [$IconKat1Off, $hIcon1, $hIcon2], _
    [$IconKat2Off, $hIcon1, $hIcon2], _
    [$IconKat3Off, $hIcon1, $hIcon2], _
    [$IconKat4Off, $hIcon1, $hIcon2]]

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

    ; Jetzt kann das GUI angezeigt werden
    GUISetState(@SW_SHOW)

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

    While True
    Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE
    Exit
    Case $GUI_EVENT_MOUSEMOVE
    _MouseOver()
    EndSwitch
    WEnd

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

    Func _MouseOver()
    Static $Hovered = 0
    Local $aCursor = GUIGetCursorInfo()
    Local $Control = $aCursor[4]
    If $Control <> $Hovered Then
    If $Hovered Then
    For $I = 0 To UBound($aHover) - 1
    If $Hovered = $aHover[$I][0] Then
    GUICtrlSendMsg($Hovered, $STM_SETICON, $aHover[$I][1], 0)
    ExitLoop
    EndIf
    Next
    EndIf
    If $Control Then
    For $I = 0 To UBound($aHover) - 1
    If $Control = $aHover[$I][0] Then
    GUICtrlSendMsg($Control, $STM_SETICON, $aHover[$I][2], 0)
    ExitLoop
    EndIf
    Next
    EndIf
    $Hovered = $Control
    EndIf
    EndFunc

    [/autoit]
  • Hallo,

    ...konnte mich leider jetzt erst wieder melden.
    Danke nochmal für die Tipps!

    @ Großvater
    super, sieht gut aus!
    Bin noch dabei einen Text auf das jeweilige Bild zu legen.
    Meistens hat es dann geflackert, auch wenn ein Hintergrundbild existiert!
    Ich bin noch am probieren.

    Eine Frage noch:

    Kann man da auch irgendwie noch das Klick-Bild reinkriegen.
    Ich meine daß beim Klick ein drittes Bild erscheint?

    Liebe Grüße
    Ilse ;)

  • Spoiler anzeigen
    [autoit]

    #include <Misc.au3>
    $hGUI = GUICreate("MouseOverSetImage Beispiel", 514, 153, 192, 124)
    $pic1 = GUICtrlCreatePic("p1.jpg", 0, 0, 257, 153)
    GUISetState()

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

    While 1
    Switch GUIGetMsg()
    Case -3
    Exit
    EndSwitch
    mouseOverSetImage($pic1, "p1.jpg", "p2.jpg", "p3.jpg")
    WEnd

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

    Func mouseOverSetImage($ctrlID, $pic1, $pic2, $pic3)
    Local Static $hover=0
    $mPos=GUIGetCursorInfo()
    If IsArray($mPos) Then
    If $mPos[4]=$ctrlID And $hover<>1 And Not _IsPressed(01) Then
    GUICtrlSetImage($ctrlID, $pic2)
    $hover=1
    ElseIf $mPos[4]<>$ctrlID And $hover<>0 Then
    GUICtrlSetImage($ctrlID, $pic1)
    $hover=0
    ElseIf $mPos[4]=$ctrlID And $hover=1 And _IsPressed(01) Then
    GUICtrlSetImage($ctrlID, $pic3)
    $hover=2
    EndIf
    EndIf
    EndFunc

    [/autoit]
  • Hallo Ineluki,

    habe gerade dein Script probiert!
    Ich sehe keine icons! Ich brauche Icons also keine jpg!

    Kannst du bitte nochmal drüberschaun?
    Hab das ganze etwas geändert

    [autoit]


    #include <Misc.au3>
    $hGUI = GUICreate("MouseOverSetImage Beispiel", 514, 153, 192, 124)
    $pic1 = GUICtrlCreateIcon("icon01.ico", 0, 0, 257, 153)
    GUISetState()

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

    $pic1 = @ScriptDir & "\icon01.ico"
    $pic2 = @ScriptDir & "\icon02.ico"
    $pic3 = @ScriptDir & "\icon03.ico"

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

    While 1
    Switch GUIGetMsg()
    Case -3
    Exit
    EndSwitch
    mouseOverSetImage($pic1, "icon01.ico", "icon02.ico", "icon03.ico")
    WEnd

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

    Func mouseOverSetImage($ctrlID, $pic1, $pic2, $pic3)
    Local Static $hover=0
    $mPos=GUIGetCursorInfo()
    If IsArray($mPos) Then
    If $mPos[4]=$ctrlID And $hover<>1 And Not _IsPressed(01) Then
    GUICtrlSetImage($ctrlID, $pic2)
    $hover=1
    ElseIf $mPos[4]<>$ctrlID And $hover<>0 Then
    GUICtrlSetImage($ctrlID, $pic1)
    $hover=0
    ElseIf $mPos[4]=$ctrlID And $hover=1 And _IsPressed(01) Then
    GUICtrlSetImage($ctrlID, $pic3)
    $hover=2
    EndIf
    EndIf
    EndFunc

    [/autoit]

    Weiß nicht genau was ich da anpassen muß...

    Liebe Grüße
    Ilse ;)

  • Spoiler anzeigen
    [autoit]

    #include <Misc.au3>
    $hGUI = GUICreate("MouseOverSetImage Beispiel", 514, 153, 192, 124)
    $picControl = GUICtrlCreateIcon("icon01.ico", 0, 0, 257, 153)
    GUISetState()

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

    $pic1 = @ScriptDir & "\icon01.ico"
    $pic2 = @ScriptDir & "\icon02.ico"
    $pic3 = @ScriptDir & "\icon03.ico"

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

    While 1
    Switch GUIGetMsg()
    Case -3
    Exit
    EndSwitch
    mouseOverSetImage($picControl, $pic1, $pic2, $pic3)
    WEnd

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

    Func mouseOverSetImage($ctrlID, $pic1, $pic2, $pic3)
    Local Static $hover=0
    $mPos=GUIGetCursorInfo()
    If IsArray($mPos) Then
    If $mPos[4]=$ctrlID And $hover<>1 And Not _IsPressed(01) Then
    GUICtrlSetImage($ctrlID, $pic2)
    $hover=1
    ElseIf $mPos[4]<>$ctrlID And $hover<>0 Then
    GUICtrlSetImage($ctrlID, $pic1)
    $hover=0
    ElseIf $mPos[4]=$ctrlID And $hover=1 And _IsPressed(01) Then
    GUICtrlSetImage($ctrlID, $pic3)
    $hover=2
    EndIf
    EndIf
    EndFunc

    [/autoit]
  • ...leider nicht!

    Zitat

    Die Gui ist leer.
    Mit den jpg's klappt es aber nicht mit icons.

    Du hast dein Beispiel mit einem Button gemacht
    Das ging bei mir vorher auch. Das Problem:
    habe ich mehrere Buttons, dann macht das Script seltsames.

    ;)

  • Hi Ilse,

    hab Ineluki's Code modifiziert und mit deinem obigem Skript kombiniert.
    Müsste jetzt wie gewünscht laufen ;)

    Spoiler anzeigen
    [autoit]

    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #include <ButtonConstants.au3>
    #Include <Array.au3>
    #include <Misc.au3>

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

    $Gui_Main = GUICreate("Gui_Main", 405, 400, 302, 218)
    $IconKat1Off = GUICtrlCreateIcon("icon01.ico", -1, 48, 108, 219, 52)
    $IconKat1Off_hover = 0
    $IconKat2Off = GUICtrlCreateIcon("icon01.ico", -1, 48, 164, 219, 52)
    $IconKat2Off_hover = 0
    $IconKat3Off = GUICtrlCreateIcon("icon01.ico", -1, 48, 220, 219, 52)
    $IconKat3Off_hover = 0
    $IconKat4Off = GUICtrlCreateIcon("icon01.ico", -1, 48, 280, 219, 52)
    $IconKat4Off_hover = 0
    $IconEndeoff = GUICtrlCreateIcon("iconEndeoff.ico", -1, 572, 36, 48, 48)
    GUISetState(@SW_SHOW)

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

    $Bild1 = @ScriptDir & "\Icon01.ico"
    $Bild2 = @ScriptDir & "\icon02.ico"
    $Bild3 = @ScriptDir & "\icon03.ico"

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

    While 1
    $nMsg = GUIGetMsg()
    mouseOverSetImage($IconKat1Off, $Bild1, $Bild2, $Bild3, $IconKat1Off_hover)
    mouseOverSetImage($IconKat2Off, $Bild1, $Bild2, $Bild3, $IconKat2Off_hover)
    mouseOverSetImage($IconKat3Off, $Bild1, $Bild2, $Bild3, $IconKat3Off_hover)
    mouseOverSetImage($IconKat4Off, $Bild1, $Bild2, $Bild3, $IconKat4Off_hover)
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit

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

    EndSwitch
    WEnd

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

    Func mouseOverSetImage($ctrlID, $pic1, $pic2, $pic3, ByRef $hover)
    $mPos=GUIGetCursorInfo()
    If IsArray($mPos) Then
    If $mPos[4]=$ctrlID And $hover<>1 And Not _IsPressed(01) Then
    GUICtrlSetImage($ctrlID, $pic2)
    $hover=1
    ElseIf $mPos[4]<>$ctrlID And $hover<>0 Then
    GUICtrlSetImage($ctrlID, $pic1)
    $hover=0
    ElseIf $mPos[4]=$ctrlID And $hover=1 And _IsPressed(01) Then
    GUICtrlSetImage($ctrlID, $pic3)
    $hover=2
    EndIf
    EndIf
    EndFunc

    [/autoit]
  • Guten Morgen,

    warum soll man denn die Mainloop mit unbedingten Funktionsaufrufen belasten, wenn das Ganze auch ereignisgesteuert (event-driven) funktioniert?

    Spoiler anzeigen
    [autoit]

    #include <GUIConstantsEx.au3>

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

    ; Ein paar Konstanten
    Global Const $STM_SETICON = 0x0170
    Global Const $STM_GETICON = 0x0171
    Global Const $STM_SETIMAGE = 0x0172
    Global Const $STM_GETIMAGE = 0x0173

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

    Global Const $IMAGE_BITMAP = 0
    Global Const $IMAGE_ICON = 1
    Global Const $IMAGE_CURSOR = 2

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

    ; Icons in Dummy GUI laden und auslesen
    GUICreate("Dummy")
    GUICtrlCreateIcon(@WindowsDir & "\cursors\horse.ani", -1, 0, 0, 32, 32)
    $hIcon1 = GUICtrlSendMsg(-1, $STM_GETICON, 0, 0)
    GUICtrlCreateIcon(@WindowsDir & "\cursors\dinosaur.ani", -1, 0, 0, 32, 32)
    $hIcon2 = GUICtrlSendMsg(-1, $STM_GETICON, 0, 0)
    GUICtrlCreateIcon(@WindowsDir & "\cursors\dinosau2.ani", -1, 0, 0, 32, 32)
    $hIcon3 = GUICtrlSendMsg(-1, $STM_GETICON, 0, 0)

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

    ; Main GUI
    $Gui_Main = GUICreate("Gui_Main", 240, 275)
    $IconKat1Off = GUICtrlCreateIcon("", -1, 20, 20, 32, 32)
    GUICtrlSendMsg(-1, $STM_SETICON, $hIcon1, 0)
    $IconKat2Off = GUICtrlCreateIcon("", -1, 20, 72, 32, 32)
    GUICtrlSendMsg(-1, $STM_SETICON, $hIcon3, 0)
    $IconKat3Off = GUICtrlCreateIcon("", -1, 20, 124, 32, 32)
    GUICtrlSendMsg(-1, $STM_SETICON, $hIcon2, 0)
    $IconKat4Off = GUICtrlCreateIcon("", -1, 20, 176, 32, 32)
    GUICtrlSendMsg(-1, $STM_SETICON, $hIcon3, 0)
    GUICtrlCreateButton("Testbutton", 20, 228, 200, 25)

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

    ; Array für Hovercontrols aufbauen [ControlID, Normales Bild, Mouseover Bild, Clicked Bild]
    Dim $aHover[4][4] = [ _
    [$IconKat1Off, $hIcon1, $hIcon2, $hIcon3], _
    [$IconKat2Off, $hIcon3, $hIcon2, $hIcon1], _
    [$IconKat3Off, $hIcon2, $hIcon3, $hIcon1], _
    [$IconKat4Off, $hIcon3, $hIcon1, $hIcon2]]

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

    ; Jetzt kann das GUI angezeigt werden
    GUISetState(@SW_SHOW)

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

    While True
    $iMsg = GUIGetMsg()
    Switch $iMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $GUI_EVENT_MOUSEMOVE
    _MouseOver($iMsg)
    Case $GUI_EVENT_PRIMARYDOWN
    _MouseOver($iMsg)
    Case $GUI_EVENT_PRIMARYUP
    _MouseOver($iMsg)
    EndSwitch
    WEnd

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

    Func _MouseOver($Event)
    Static $Hovered = 0
    Local $aCursor = GUIGetCursorInfo()
    Local $Control = $aCursor[4]
    Switch $Event
    Case $GUI_EVENT_MOUSEMOVE
    If $Control <> $Hovered Then
    If $Hovered Then
    For $I = 0 To UBound($aHover) - 1
    If $Hovered = $aHover[$I][0] Then
    GUICtrlSendMsg($Hovered, $STM_SETICON, $aHover[$I][1], 0)
    ExitLoop
    EndIf
    Next
    EndIf
    If $Control Then
    For $I = 0 To UBound($aHover) - 1
    If $Control = $aHover[$I][0] Then
    GUICtrlSendMsg($Control, $STM_SETICON, $aHover[$I][2], 0)
    ExitLoop
    EndIf
    Next
    EndIf
    $Hovered = $Control
    EndIf
    Case $GUI_EVENT_PRIMARYDOWN
    If $Hovered Then
    For $I = 0 To UBound($aHover) - 1
    If $Hovered = $aHover[$I][0] Then
    GUICtrlSendMsg($Hovered, $STM_SETICON, $aHover[$I][3], 0)
    ExitLoop
    EndIf
    Next
    EndIf
    Case $GUI_EVENT_PRIMARYUP
    If $Hovered Then
    For $I = 0 To UBound($aHover) - 1
    If $Hovered = $aHover[$I][0] Then
    GUICtrlSendMsg($Hovered, $STM_SETICON, $aHover[$I][2], 0)
    ExitLoop
    EndIf
    Next
    EndIf
    EndSwitch
    EndFunc ;==>_MouseOver

    [/autoit]