_GUICtrlSlider_SetPos bei verstecktem Fenster verwenden geht nicht

  • Servus, kann es sein, dass

    [autoit]

    _GUICtrlSlider_SetPos

    [/autoit]


    nicht mit versteckten Fenstern funktioniert? Wenn das Fenster geöffnet ist, dann funktioniert es Problemlos. Gibt es dafür einen Workaround oder so etwas?

    Da es hier doch einige falsch machen:

    Zitat von einem User dieses Forums

    Die Standard-Standart eines Flamingos ist einbeinig. ;)

  • Für euch immer ;) Aber bisschen was arbeiten müsst ihr schon :D

    Spoiler anzeigen
    [autoit]


    #include-once
    #include <GuiSlider.au3>

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

    Global $sVolumeMixerTitle = ""

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

    ; #FUNCTION# ====================================================================================================================
    ; Name ..........: _Win7SH_Startup
    ; Description ...: Startup Win7SoundHandler: Declare Variables; Get the name of the Volume Mixer in the right language
    ; Syntax ........: _Win7SH_Startup()
    ; Parameters ....:
    ; Return values .: $sVolumeMixerTitle - The Title of the Volume Mixer Window in the Systemlanguage.
    ; Author ........: Rafael K. (Joriktos, autoit.de)
    ; Modified ......:
    ; Remarks .......:
    ; Related .......:
    ; Link ..........:
    ; Example .......: No
    ; ===============================================================================================================================
    Func _Win7SH_Startup()
    OnAutoItExitRegister("_Win7SH_Shutdown")
    Global $bSndVolClose = False
    Global $iSndVolStartups = 0
    Global $asPrograms[2][2] = [[0]]
    Global $hPID = Run("sndvol -r", @SystemDir, @SW_HIDE)
    $sVolumeMixerTitle = _GetTitleFromPID($hPID)
    ProcessClose($hPID)

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

    $sVolumeMixerTitle = StringSplit($sVolumeMixerTitle, " - ", 1)
    $sVolumeMixerTitle = $sVolumeMixerTitle[1]

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

    Local $iCountProgramsInstance = 0
    Local $iCountPrograms = 1

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

    Global $sMuteText = ""
    Global $aPrograms
    Global $aProgramInfo[2] = [0]
    $sMuteText = _GetMuteText()

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

    Return $sVolumeMixerTitle
    EndFunc ;==>_Win7SH_Startup

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

    ; #FUNCTION# ====================================================================================================================
    ; Name ..........: _Win7SH_Shutdown
    ; Description ...: Closes SndVol.exe, if it's needed.
    ; Syntax ........: _Win7SH_Shutdown()
    ; Parameters ....:
    ; Return values .: None
    ; Author ........: Rafael K. (Joriktos, autoit.de)
    ; Modified ......:
    ; Remarks .......:
    ; Related .......:
    ; Link ..........:
    ; Example .......: No
    ; ===============================================================================================================================
    Func _Win7SH_Shutdown()
    $iSndVolStartups = 1
    _SndVolShutdown()
    EndFunc

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

    ; #FUNCTION# ====================================================================================================================
    ; Name ..........: _GetTitleFromPID
    ; Description ...: Returns the Name of a Window to a PID.
    ; Syntax ........: _GetTitleFromPID($hPID)
    ; Parameters ....: $hPID - A handle value.
    ; Return values .: $sTitle - The Title of the Volume Mixer Window in the Systemlanguage.
    ; Author ........:
    ; Modified ......: Rafael K. (Joriktos, autoit.de)
    ; Remarks .......:
    ; Related .......:
    ; Link ..........:
    ; Example .......: No
    ; ===============================================================================================================================
    Func _GetTitleFromPID($hPID)
    $sTitle = ""
    $stPID = DllStructCreate("int")
    Do
    $aWinList = WinList()
    For $i = 1 To $aWinList[0][0]
    If $aWinList[$i][0] <> "" Then
    DllCall("user32.dll", "int", "GetWindowThreadProcessId", "hwnd", $aWinList[$i][1], "ptr", DllStructGetPtr($stPID))
    If DllStructGetData($stPID, 1) = $hPID Then
    $sTitle = $aWinList[$i][0]
    ExitLoop
    EndIf
    EndIf
    Next
    Sleep(100)
    Until $sTitle <> ""
    ProcessClose($hPID)
    Return $sTitle
    EndFunc ;==>_GetTitleFromPID

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

    ; #FUNCTION# ====================================================================================================================
    ; Name ..........: _GetMuteText
    ; Description ...: Returns the text before the Programname (ex. English: "Mute"; ex. German: "Stumm für")
    ; Syntax ........: _GetMuteText()
    ; Parameters ....:
    ; Return values .: $sMuteText - The text before the Programname (ex. English: "Mute"; ex. German: "Stumm für")
    ; Author ........: Rafael K. (Joriktos, autoit.de)
    ; Modified ......:
    ; Remarks .......:
    ; Related .......:
    ; Link ..........:
    ; Example .......: No
    ; ===============================================================================================================================
    Func _GetMuteText()
    Local $sRandomProgramName
    Local $iNamePosition
    _SndVolStartup()
    Local $sRandomProgramName = ControlGetText($sVolumeMixerTitle, "", 301)
    $asPrograms = _MixerGetPrograms()
    _SndVolShutdown()
    For $iCountPrograms = 1 To $asPrograms[0][0]
    $iNamePosition = StringInStr($asPrograms[$iCountPrograms][0], $sRandomProgramName)
    If $iNamePosition <> 0 Then
    ExitLoop
    EndIf
    Next
    $sMuteText = StringLeft($asPrograms[$iCountPrograms][0], $iNamePosition - 1)
    Return $sMuteText
    EndFunc ;==>_GetMuteText

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

    ; #FUNCTION# ====================================================================================================================
    ; Name ..........: _SndVolStartup
    ; Description ...: Start the Volume Mixer or get the PID of an opened one.
    ; Syntax ........: _SndVolStartup()
    ; Parameters ....:
    ; Return values .:
    ; Author ........: Rafael K. (Joriktos, autoit.de)
    ; Modified ......:
    ; Remarks .......:
    ; Related .......:
    ; Link ..........:
    ; Example .......: No
    ; ===============================================================================================================================
    Func _SndVolStartup()
    If $sVolumeMixerTitle = "" Then
    Return 0
    Else
    If WinExists($sVolumeMixerTitle) Then
    $hPID = WinGetProcess($sVolumeMixerTitle)
    Else
    $hPID = Run("SndVol -r", @SystemDir, @SW_HIDE)
    $bSndVolClose = True
    WinWait($sVolumeMixerTitle)
    EndIf
    $iSndVolStartups += 1
    EndIf
    EndFunc ;==>_SndVolStartup

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

    ; #FUNCTION# ====================================================================================================================
    ; Name ..........: _SndVolShutdown
    ; Description ...: Close the Volume Mixer if _SndVolStartup() opened a new Instance of Volume Mixer, else do nothing.
    ; Syntax ........: _SndVolShutdown()
    ; Parameters ....:
    ; Return values .:
    ; Author ........: Rafael K. (Joriktos, autoit.de)
    ; Modified ......:
    ; Remarks .......:
    ; Related .......:
    ; Link ..........:
    ; Example .......: No
    ; ===============================================================================================================================
    Func _SndVolShutdown()
    If $sVolumeMixerTitle = "" Then
    Return 0
    Else
    If $iSndVolStartups = 1 Then
    If $bSndVolClose = True Then
    ProcessClose($hPID)
    $bSndVolClose = False
    EndIf
    EndIf
    If $iSndVolStartups > 0 Then
    $iSndVolStartups -= 1
    EndIf
    EndIf
    EndFunc ;==>_SndVolShutdown

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

    ; #FUNCTION# ====================================================================================================================
    ; Name ..........: _MixerGetPrograms
    ; Description ...:
    ; Syntax ........: _MixerGetPrograms()
    ; Parameters ....:
    ; Return values .: 0 - You have to use _Win7SH_Startup() first.
    ; $asPrograms - An Array. $asPrograms[0][0] = Number of Programs; $asPrograms[n][0] = Programname; $asPrograms[n][1] = Volume
    ; Author ........: Rafael K. (Joriktos, autoit.de)
    ; Modified ......:
    ; Remarks .......:
    ; Related .......:
    ; Link ..........:
    ; Example .......: No
    ; ===============================================================================================================================
    Func _MixerGetPrograms()
    If $sVolumeMixerTitle = "" Then
    Return 0
    Else
    _SndVolStartup()
    $iCountProgramsInstance = 0
    $iCountPrograms = 1
    While 1
    $iCountProgramsInstance += 2
    If $sMuteText = "" Then
    $asPrograms[$iCountPrograms][0] = ControlGetText($sVolumeMixerTitle, "", "[CLASS:ToolbarWindow32; INSTANCE:" & $iCountProgramsInstance & "]")
    Else
    $asPrograms[$iCountPrograms][0] = StringReplace(ControlGetText($sVolumeMixerTitle, "", "[CLASS:ToolbarWindow32; INSTANCE:" & $iCountProgramsInstance & "]"), $sMuteText, "", 1, 1)
    EndIf
    If $asPrograms[$iCountPrograms][0] = "" Then
    If $iCountPrograms = 1 Then
    ReDim $asPrograms[2][2]
    $asPrograms[0][0] = 0
    $asPrograms[1][1] = ""
    Else
    ReDim $asPrograms[$iCountPrograms][2]
    EndIf
    ExitLoop
    Else
    $asPrograms[0][0] = $iCountPrograms
    $asPrograms[$iCountPrograms][1] = 100 - _GUICtrlSlider_GetPos(ControlGetHandle($sVolumeMixerTitle, "", "[CLASS:msctls_trackbar32; INSTANCE:" & $iCountPrograms & "]"))
    $iCountPrograms += 1
    ReDim $asPrograms[$iCountPrograms + 1][2]
    EndIf
    WEnd
    _SndVolShutdown()
    Return $asPrograms
    EndIf
    EndFunc ;==>_MixerGetPrograms

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

    ; #FUNCTION# ====================================================================================================================
    ; Name ..........: _GetProgramSoundlevel
    ; Description ...:
    ; Syntax ........: _GetProgramSoundlevel($sProgram[, $iFullTitle = False])
    ; Parameters ....: $sProgram - A string value.
    ; $iFullTitle - [optional] An integer value. Default is False.
    ; Return values .: 0 - You have to use _Win7SH_Startup() first.
    ; $aProgramInfo - An Array. $aProgramInfo[0] = Programname; $aProgramInfo[1] = Volume (0-100)
    ; Author ........: Rafael K. (Joriktos, autoit.de)
    ; Modified ......:
    ; Remarks .......:
    ; Related .......:
    ; Link ..........:
    ; Example .......: No
    ; ===============================================================================================================================
    Func _GetProgramSoundlevel($sProgram, $iFullTitle = False)
    If $sVolumeMixerTitle = "" Then
    Return 0
    Else
    _SndVolStartup()
    $aPrograms = _MixerGetPrograms()
    $aProgramInfo[0] = 0
    $aProgramInfo[1] = 0
    If $iFullTitle = True Then
    For $iLoopCount = 1 To $aPrograms[0][0]
    If $aPrograms[$iLoopCount][0] = $sProgram Then
    $aProgramInfo[0] = $aPrograms[$iLoopCount][0]
    $aProgramInfo[1] = $aPrograms[$iLoopCount][1]
    ExitLoop
    EndIf
    Next
    EndIf
    If $iFullTitle = False Then
    For $iLoopCount = 1 To $aPrograms[0][0]
    If StringInStr($aPrograms[$iLoopCount][0], $sProgram) <> 0 Then
    $aProgramInfo[0] = $aPrograms[$iLoopCount][0]
    $aProgramInfo[1] = $aPrograms[$iLoopCount][1]
    ExitLoop
    EndIf
    Next
    EndIf
    _SndVolShutdown()
    Return $aProgramInfo
    EndIf
    _SndVolShutdown()
    EndFunc ;==>_GetProgramSoundlevel

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

    Func _SetProgramSoundlevel($sProgram, $iVolume, $iFullTitle = False)
    If $sVolumeMixerTitle = "" Then
    Return 0
    ElseIf Not StringIsDigit($iVolume) Then
    SetError(1)
    Else
    _SndVolStartup()
    $aPrograms = _MixerGetPrograms()
    $aProgramInfo[0] = 0
    $aProgramInfo[1] = 0
    If $iFullTitle = True Then
    For $iLoopCount = 1 To $aPrograms[0][0]
    If $aPrograms[$iLoopCount][0] = $sProgram Then
    $aProgramInfo[0] = $aPrograms[$iLoopCount][0]
    $aProgramInfo[1] = $aPrograms[$iLoopCount][1]
    ExitLoop
    EndIf
    Next
    EndIf
    If $iFullTitle = False Then
    For $iLoopCount = 1 To $aPrograms[0][0]
    If StringInStr($aPrograms[$iLoopCount][0], $sProgram) <> 0 Then
    $aProgramInfo[0] = $aPrograms[$iLoopCount][0]
    $aProgramInfo[1] = $aPrograms[$iLoopCount][1]
    ExitLoop
    EndIf
    Next
    EndIf
    If $aProgramInfo[0] <> "" Then
    _GUICtrlSlider_SetPos(ControlGetHandle($sVolumeMixerTitle, "", "[CLASS:msctls_trackbar32; INSTANCE:" & $iLoopCount & "]"), 100 - $iVolume)
    _SndVolShutdown()
    Return $aProgramInfo
    Else
    _SndVolShutdown()
    SetError(2)
    Return 0
    EndIf
    EndIf
    EndFunc ;==>_SetProgramSoundlevel

    [/autoit]

    Ich bin gerade dabei ein besseres Soundmanagement für Win7/8 zu basteln ;)
    Ihr müsst euch dafür _SetProgramSoundlevel (letzte Funktion) anschauen.

    Da es hier doch einige falsch machen:

    Zitat von einem User dieses Forums

    Die Standard-Standart eines Flamingos ist einbeinig. ;)

    Einmal editiert, zuletzt von Joriktos (24. April 2013 um 19:40)

  • Ich weiß, es sind noch nicht ganz 24 Stunden um, aber Hilfe wäre gerade echt gut, da ich gerade etwas Zeit habe^^
    Übrigens funktioniert _GUICtrlSlider_GetPos immer einwandfrei, nur das SetPos macht Probleme, ich habe mir dazu auch Win7_Sound von BugFix angeschaut, aber das hilft mir auch nicht weiter, weil dort scheint es zu funktionieren und eigentlich ist es doch bei mir sehr gleich gelöst, oder habe ich da etwas übersehen? Übrigens mach ich das alles, damit der Benutzer weiterhin den Lautstärkemixer verwenden kann, was ja bei BugFix' UDF nicht funktioniert, außerdem möchte ich weitere nette Erweiterungen einbauen :)

    Da es hier doch einige falsch machen:

    Zitat von einem User dieses Forums

    Die Standard-Standart eines Flamingos ist einbeinig. ;)

    • Offizieller Beitrag

    Sollen wir jetzt raten, was du wann und wo mit den UDF-Funktionen anstellst? Wo ist der ausführbare Testscriptteil?
    Ich sehe im Script nur Funtionen und die werden nirgends aufgerufen. ;)

  • Bitteschön, meine Soundcheck.au3 :D War nur für mich gedacht, deshalb nicht so übersichtlich...

    [autoit]


    #include <Array.au3>
    #include <ButtonConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <WindowsConstants.au3>
    #include <GuiSlider.au3>
    #include "Win7SoundHandler.au3"

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

    Opt("WinTitleMatchMode", 2)
    Global $sVolumeMixerTitle = ""

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

    #region ### START Koda GUI section ### Form=
    $Form1 = GUICreate("Dialog", 308, 272, 735, 289)
    $Button1 = GUICtrlCreateButton("Run", 23, 17, 75, 25)
    $Button2 = GUICtrlCreateButton("Get Apps", 115, 17, 75, 25)
    $Button3 = GUICtrlCreateButton("", 207, 17, 75, 25)
    $Button4 = GUICtrlCreateButton("", 23, 60, 75, 25)
    $Button5 = GUICtrlCreateButton("Volume", 115, 60, 75, 25)
    $Button6 = GUICtrlCreateButton("", 207, 60, 75, 25)
    GUISetState(@SW_SHOW)
    #endregion ### END Koda GUI section ###

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Button1
    _Win7SH_Startup()
    Case $Button2
    $bla = _MixerGetPrograms()
    _ArrayDisplay($bla)
    Case $Button3
    $bla2 = _GetProgramSoundlevel("Winamp")
    MsgBox(0, "", $bla2[0] & @CRLF & $bla2[1])
    Case $Button4
    Case $Button5
    $sProgram = InputBox("", "Program:")
    $iVolume = InputBox("", "Volume:")
    $Error = _SetProgramSoundlevel($sProgram, $iVolume)
    ;MsgBox(0, "", $Error & @CRLF & @error)
    EndSwitch
    WEnd

    [/autoit]

    Da es hier doch einige falsch machen:

    Zitat von einem User dieses Forums

    Die Standard-Standart eines Flamingos ist einbeinig. ;)

  • Push

    -Ich suche immernoch ein Workaround ;)


    Edit: Also es liegt nicht direkt an _GUICtrlSlider_SetPos, sondern es geht auch nicht, wenn ich es mit einem direkten DllCall anspreche...

    [autoit]

    DllCall("user32.dll", "lresult", "SendMessageW", "hwnd", ControlGetHandle($sVolumeMixerTitle, "", "[CLASS:msctls_trackbar32; INSTANCE:" & $iLoopCount & "]"), "uint", $TBM_SETPOS, "wparam", True, "lparam", 100 - $iVolume)

    [/autoit]


    Edit2: Es funktioniert doch, aber es gibt ein anderes Problem: Es wird zwar der Slider verschoben, dies hat aber keinerlei auswirkung auf die Lautstärke und wird auch nach dem schließen vom Lautstärkemixer wieder verworfen, hat jemand eine Idee, warum das so ist?

    Da es hier doch einige falsch machen:

    Zitat von einem User dieses Forums

    Die Standard-Standart eines Flamingos ist einbeinig. ;)

    2 Mal editiert, zuletzt von Joriktos (26. April 2013 um 22:25)