Progressbar beim anklicken verstellen

  • Hallo Leute,
    ist es irgendwie möglich die Progress Bar beim anklicken zu verstellen?
    Ich habe hier einen Musikplayer bei dem ich gerne den Song mit anklicken auf die Progress Bar verstellen möchte.
    So ähnlich wie vor oder rückspulen bei Media Player.
    Leider habe ich absolut kein Plan wie ich das realisieren könnte.
    Vielleicht hat jemand eine Idee und kann mir da weiterhelfen?

    Hier bis jetzt mein CODE

    Spoiler anzeigen
    [autoit]

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

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

    Global $XS_n

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

    #Region ### START Koda GUI section ### Form=
    $Form1 = GUICreate("Mp3 Player", 333, 437, -1, -1, BitOR($WS_MINIMIZEBOX,$WS_SYSMENU,$WS_POPUP,$WS_GROUP,$WS_CLIPSIBLINGS))
    FileInstall("C:\Windows\Web\Screen\img105.jpg", ".\Background.jpeg")
    $Pic1 = GUICtrlCreatePic("Background.jpeg", 0, 0, 332, 436, BitOR($SS_NOTIFY, $WS_GROUP, $WS_CLIPSIBLINGS))
    GUICtrlSetState(-1, $GUI_DISABLE)
    $DateiButton = GUICtrlCreateButton("...", 8, 8, 60, 25)
    $PlayButton = GUICtrlCreateButton("Play", 74, 8, 60, 25)
    $PauseButton = GUICtrlCreateButton("Pause", 139, 8, 60, 25)
    $StopButton = GUICtrlCreateButton("Stop", 202, 8, 60, 25)
    $ExitButton = GUICtrlCreateButton("Exit", 266, 8, 60, 25)
    $DateiLabel = GUICtrlCreateLabel("Keine Datei ausgewählt", 8, 40, 319, 40)
    GUICtrlSetColor(-1, 0x00FF00)
    GUICtrlSetBkColor(-1, 0x000000)
    $ZeitLabel = GUICtrlCreateLabel("Zeit: 0 - Länge: 0 - Übrig: 0", 8, 80, 319, 17)
    GUICtrlSetColor(-1, 0x00FF00)
    GUICtrlSetBkColor(-1, 0x000000)
    $Progress1 = GUICtrlCreateProgress(8, 100, 319, 17)
    $Lautstaerke = GUICtrlCreateSlider(8, 392, 318, 37)
    GUICtrlSetData(-1, 1)
    GUICtrlSetBkColor(-1,0x000000)
    XPStyleToggle(1);turn xp themes off
    $ReiseJerusalem = GUICtrlCreateCheckbox("Spiel: Reise nach Jerusalem", 8, 360, 319, 34)
    GUICtrlSetColor($ReiseJerusalem, $COLOR_WHITE)
    GUICtrlSetBkColor($ReiseJerusalem, $GUI_BKCOLOR_TRANSPARENT)
    XPStyleToggle(0);turn XP themes on again
    GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST")
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

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

    Global $hSound, $lol, $Lenght, $Pos, $Paused = False
    Local $Ordner = 'X:\Musik'
    Local $lol = $Ordner & '\Russische Musik\ä¿ß¬«ÔѬá 80-Õ.ùáßÔý1\03_-_Afric_Simone_-_Hafanana.mp3'
    GUICtrlSetData($DateiLabel, $lol)

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

    $Read = GUICtrlRead($Lautstaerke)
    SoundSetWaveVolume($Read)

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

    While Sleep(10)
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    _SoundStop($hSound)
    Exit
    Case $DateiButton
    ;~ $lol = FileOpenDialog("", @UserProfileDir & "\Music", "(*.mp3)", 1)
    $lol = FileOpenDialog("", $Ordner, "(*.mp3)", 1)
    GUICtrlSetData($DateiLabel, $lol)
    Case $PlayButton
    If IsArray($hSound) And $hSound[3] > 0 Then _SoundClose($hSound)
    $hSound = _SoundOpen($lol)
    If @error Then
    MsgBox(48, "Fehler", "Es wurde keine Datei ausgewählt!")
    Else
    $Lenght = _SoundLength($hSound)
    _SoundPlay($hSound)
    $Paused = False
    EndIf
    GUICtrlSetData($DateiLabel, $lol)
    If _IsChecked($ReiseJerusalem) Then $Position = _SoundPos($hSound, 2) + Random(15, 30, 1)*1000
    Case $StopButton
    If IsArray($hSound) And $hSound[3] > 0 Then
    _SoundStop($hSound)
    _SoundClose($hSound)
    EndIf
    Case $ExitButton
    _SoundStop($hSound)
    Exit
    Case $PauseButton
    $Paused = Not $Paused
    If $Paused = True Then _SoundPause($hSound)
    If $Paused = False Then
    _SoundResume ($hSound)
    If _IsChecked($ReiseJerusalem) Then $Position = _SoundPos($hSound, 2) + Random(15, 30, 1)*1000
    EndIf
    Case $Lautstaerke
    $Read = GUICtrlRead($Lautstaerke)
    SoundSetWaveVolume($Read)
    Case $ReiseJerusalem
    $Position = _SoundPos($hSound, 2) + Random(15, 30, 1)*1000
    Case $Progress1
    Hier sollte irgendwie was passieren
    EndSwitch

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

    $Maximale_Laenge = _SoundLength($hSound, 2)
    $Aktuelle_Position = _SoundPos($hSound, 2)
    $Fortschritt = $Aktuelle_Position * 100 / $Maximale_Laenge
    If (GUICtrlRead($Progress1) + 1) <> $Fortschritt Then
    GUICtrlSetData($Progress1, $Fortschritt)
    EndIf

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

    $Pos = _SoundPos($hSound)
    Local $Hours, $Mins, $Secs
    __SoundTicksToTime($Maximale_Laenge - $Aktuelle_Position, $Hours, $Mins, $Secs)
    $Left = StringFormat("%02i:%02i:%02i", $Hours, $Mins, $Secs)
    $bla = "Zeit: " & $Pos & " - Länge: " & $Lenght & " - Übrig: " & $Left
    If GUICtrlRead($ZeitLabel) <> $bla Then GUICtrlSetData($ZeitLabel, $bla)
    If _IsChecked($ReiseJerusalem) And _SoundPos($hSound, 2) > $Position Then
    _SoundPause($hSound)
    $Paused = True
    $Position = _SoundPos($hSound, 2) + Random(15, 30, 1)*1000
    EndIf
    If _IsChecked($ReiseJerusalem) Then ConsoleWrite("Aktuelle Position: " & Sec2Time(_SoundPos($hSound, 2)/1000) & ' bis ' & Sec2Time($Position/1000) & " _SoundStatus: " & _SoundStatus($hSound) & @CRLF)
    WEnd

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

    Func XPStyleToggle($Off = 1)
    If Not StringInStr(@OSTYPE, "WIN32_NT") Then Return 0

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

    If $Off Then
    $XS_n = DllCall("uxtheme.dll", "int", "GetThemeAppProperties")
    DllCall("uxtheme.dll", "none", "SetThemeAppProperties", "int", 0)
    Return 1
    ElseIf IsArray($XS_n) Then
    DllCall("uxtheme.dll", "none", "SetThemeAppProperties", "int", $XS_n[0])
    $XS_n = ""
    Return 1
    EndIf
    Return 0
    EndFunc

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

    Func WM_NCHITTEST($hWnd, $iMsg, $iwParam, $ilParam)
    If ($hWnd = $Form1) And ($iMsg = $WM_NCHITTEST) Then Return $HTCAPTION
    EndFunc

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

    Func Sec2Time($nr_sec)
    $sec2time_hour = Int($nr_sec / 3600)
    $sec2time_min = Int(($nr_sec - $sec2time_hour * 3600) / 60)
    $sec2time_sec = $nr_sec - $sec2time_hour * 3600 - $sec2time_min * 60
    Return StringFormat('%02d:%02d:%02d', $sec2time_hour, $sec2time_min, $sec2time_sec)
    EndFunc ;==>Sec2Time

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

    Func _IsChecked($iControlID)
    Return BitAND(GUICtrlRead($iControlID), $GUI_CHECKED) = $GUI_CHECKED
    EndFunc ;==>_IsChecked

    [/autoit]
  • Mit Progressbar könnte man es so lösen:

    Spoiler anzeigen
    [autoit]

    #include <GUIConstantsEx.au3>

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

    $hGUI = GUICreate("Progress", 200, 50)
    $hProgress = GUICtrlCreateProgress(5, 5, 190, 20)

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

    GUISetState()

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

    While 1
    Switch GUIGetMsg()
    Case -3
    Exit
    Case $GUI_EVENT_PRIMARYUP
    $aCurInf = GUIGetCursorInfo($hGUI)
    $aPos = ControlGetPos($hGUI, "", $hProgress)
    If $aCurInf[4] = $hProgress Then GUICtrlSetData($hProgress, 100 / $aPos[2] * ($aCurInf[0] - $aPos[0]))
    EndSwitch
    WEnd

    [/autoit]
    UNPLEASANT SPOILER

    You just lost the game!

  • Hier ein Ansatz:

    [autoit]

    #Include <GUIConstantsEx.au3>
    #Include <WindowsConstants.au3>

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

    AutoItSetOption("MouseCoordMode", 2)

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

    #Region ### START Koda GUI section ### Form=
    $Form1 = GUICreate("Mp3 Player", 333, 437, -1, -1, BitOR($WS_MINIMIZEBOX,$WS_SYSMENU,$WS_POPUP,$WS_GROUP,$WS_CLIPSIBLINGS))
    $Progress1 = GUICtrlCreateProgress(8, 100, 319, 17)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

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

    Global $iProgress = 0, $bMP = False, $iProgressMax = 319

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

    AdlibRegister("Playing")

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

    Do
    Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE
    AdlibUnRegister("Playing")
    GUIDelete()
    Exit
    EndSwitch
    $a = GUIGetCursorInfo ($Form1)
    If $a[4] = $Progress1 And $a[2] Then
    $bMP = True
    $aPos = ControlGetPos($Form1, "", $Progress1)
    $iProgress = Int((-8 + MouseGetPos(0)) / $iProgressMax * 100)
    GUICtrlSetData($Progress1, $iProgress)
    Else
    $bMP = False
    EndIf
    Until False

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

    Func Playing()
    If Not $bMP Then
    GUICtrlSetData($Progress1, $iProgress)
    $iProgress += 0.25
    If $iProgress > 100 Then AdlibUnRegister("Playing")
    EndIf
    EndFunc

    [/autoit]

    Gruß,
    UEZ

    Auch am Arsch geht ein Weg vorbei...

    ¯\_(ツ)_/¯

    • Offizieller Beitrag

    Hier noch mal des Beispiel von UEZ, ein bisschen erweitert.
    Dabei spielen die Maße und Position des Progressbars keine Rolle mehr.

    Spoiler anzeigen
    [autoit]

    #include <GUIConstantsEx.au3>
    #include <WinApi.au3>
    #include <WindowsConstants.au3>
    AutoItSetOption("MouseCoordMode", 2)
    #Region ### START Koda GUI section ### Form=
    $Form1 = GUICreate("Mp3 Player", 333, 437, -1, -1, BitOR($WS_MINIMIZEBOX, $WS_SYSMENU, $WS_POPUP, $WS_GROUP, $WS_CLIPSIBLINGS))
    $Progress1 = GUICtrlCreateProgress(8, 100, 319, 17)
    $hProgress = GUICtrlGetHandle($Progress1)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###
    Global $iProgress = 0, $bMP = False
    AdlibRegister("Playing")
    Do
    Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE
    AdlibUnRegister("Playing")
    GUIDelete()
    Exit
    EndSwitch
    $a = GUIGetCursorInfo($Form1)
    If $a[4] = $Progress1 And $a[2] Then
    $bMP = True
    $tpos = _WinAPI_GetMousePos(True, $hProgress)
    $iWidth = _WinAPI_GetClientWidth($hProgress)
    $iProgress = Int(DllStructGetData($tpos, 1) / $iWidth * 100)
    GUICtrlSetData($Progress1, $iProgress)
    Else
    $bMP = False
    EndIf
    Until False
    Func Playing()
    If Not $bMP Then
    GUICtrlSetData($Progress1, $iProgress)
    $iProgress += 0.25
    If $iProgress > 100 Then AdlibUnRegister("Playing")
    EndIf
    EndFunc ;==>Playing

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