Advertisement
BugFix

Untitled

Jul 28th, 2012
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 8.39 KB | None | 0 0
  1. #Region - TimeStamp
  2. ; 2012-07-29 01:01:10
  3. #EndRegion - TimeStamp
  4. #Include <Array.au3>
  5.  
  6. $a = _Win7_SoundGetAll()
  7. _ArrayDisplay($a)
  8.  
  9. ;~ ConsoleWrite( _Win7_SoundGetApp('Firefox') & @CRLF)
  10. ;~ ConsoleWrite( _Win7_SoundGetApp() & @CRLF)
  11.  
  12. ;~ ConsoleWrite( _Win7_SoundGetApp('Flash') & @CRLF)
  13. ;~ ConsoleWrite( _Win7_SoundSetApp(50, 'Firefox') & @CRLF)
  14. ;~ ConsoleWrite( _Win7_SoundGetApp('Firefox') & @CRLF)
  15.  
  16. ;===============================================================================
  17. ; Function Name....: _Win7_SoundGetAll
  18. ; Description......: Ermittelt vom Soundmixer: Anwendung, aktuelle Werte (inkl. Mastersound)
  19. ; Parameter(s).....: keine
  20. ; Requirement(s)...: OS Vista oder höher
  21. ; Return Value(s)..: 2D-Array [[Name Anwendung, Sound-Wert]]
  22. ; Author(s)........: BugFix ( bugfix@autoit.de )
  23. ;===============================================================================
  24. Func _Win7_SoundGetAll()
  25.     Local $aRet, $dll = DllOpen('user32.dll')
  26.     Local $iPID = Run("sndvol", '', @SW_MINIMIZE)
  27.     Local $oldOpt = Opt("WinTitleMatchMode", 2)
  28.     Local $hSoundMixer = WinWait("Lautstärkemixer")
  29.     Opt("WinTitleMatchMode", $oldOpt)
  30.     Local $aHWnd[1][2]
  31.     $aRet = DllCall($dll, "hwnd", "GetWindow", "hwnd", $hSoundMixer, "uint", 5)
  32.     Local $hChildMix = $aRet[0]
  33.     Local $hFirst = $hChildMix, $hAppsOuter, $hAppsInner, $hTmp, $hSub, $n = 0, $i = 0, $sText
  34.     While $hFirst <> 0x0
  35.         $aRet = DllCall($dll, "int", "GetClassNameW", "hwnd", $hFirst, "wstr", "", "int", 4096)
  36.         If $aRet[2] = 'msctls_trackbar32' Then
  37.             $aHWnd[0][0] = 'Master'
  38.             $aRet = DllCall($dll, "int", "SendMessageW", "hwnd", $hFirst, "uint", 0x400, "wparam", 0, "lparam", 0)
  39.             $aHWnd[0][1] = 100 - $aRet[0]
  40.         EndIf
  41.         $aRet = DllCall($dll, "hwnd", "GetWindow", "hwnd", $hFirst, "uint", 2)
  42.         $hFirst = $aRet[0]
  43.     WEnd
  44.     $hTmp = __Get_hTmp($dll, $hSoundMixer)
  45.     While $hTmp <> 0x0
  46.         If $aHWnd[UBound($aHWnd)-1][0] <> '' Then ReDim $aHWnd[UBound($aHWnd)+1][2]
  47.         $aHWnd[UBound($aHWnd)-1][0] = $hTmp
  48.         $aRet = DllCall($dll, "hwnd", "GetWindow", "hwnd", $hTmp, "uint", 2)
  49.         $hTmp = $aRet[0]
  50.         $i += 1
  51.     WEnd
  52.     For $i = 1 To UBound($aHWnd)-1
  53.         $aRet = DllCall($dll, "hwnd", "GetWindow", "hwnd", $aHWnd[$i][0], "uint", 5)
  54.         $hSub = $aRet[0]
  55.         $n = 0
  56.         While $hSub <> 0x0
  57.             $n += 1
  58.             If $n = 3 Then
  59.                 $aRet = DllCall($dll, "int", "GetWindowTextW", "hwnd", $hSub, "wstr", "", "int", 4096)
  60.                 $sText = $aRet[2]
  61.             ElseIf $n = 5 Then
  62.                 $aHWnd[$i][0] = $sText
  63.                 $aRet = DllCall($dll, "int", "SendMessageW", "hwnd", $hSub, "uint", 0x400, "wparam", 0, "lparam", 0)
  64.                 $aHWnd[$i][1] = 100 - $aRet[0]
  65.                 ExitLoop
  66.             EndIf
  67.             $aRet = DllCall($dll, "hwnd", "GetWindow", "hwnd", $hSub, "uint", 2)
  68.             $hSub = $aRet[0]
  69.         WEnd
  70.     Next
  71.     DllClose($dll)
  72.     ProcessClose($iPID)
  73.     Return $aHWnd
  74. EndFunc  ;==>_Win7_SoundGetAll
  75.  
  76. ;===============================================================================
  77. ; Function Name....: _Win7_SoundGetApp
  78. ; Description......: Ermittelt von Anwendung den aktuelle Sound-Wert
  79. ; Parameter(s).....: $_sApp  Name der Anwendung, Leerstring (Standard) gibt Mastervolume zurück
  80. ; Requirement(s)...: OS Vista oder höher
  81. ; Return Value(s)..: linearer Wert des Sound-Sliders
  82. ; Author(s)........: BugFix ( bugfix@autoit.de )
  83. ;===============================================================================
  84. Func _Win7_SoundGetApp($_sApp='')
  85.     Local $aRet, $dll = DllOpen('user32.dll')
  86.     Local $iPID = Run("sndvol", '', @SW_MINIMIZE)
  87.     Local $oldOpt = Opt("WinTitleMatchMode", 2)
  88.     Local $hSoundMixer = WinWait("Lautstärkemixer")
  89.     Opt("WinTitleMatchMode", $oldOpt)
  90.     Local $aHWnd[1][2]
  91.     $aRet = DllCall($dll, "hwnd", "GetWindow", "hwnd", $hSoundMixer, "uint", 5)
  92.     Local $hChildMix = $aRet[0]
  93.     Local $hFirst = $hChildMix, $hAppsOuter, $hAppsInner, $hTmp, $hSub, $n = 0, $i = 0, $sText
  94.     While $hFirst <> 0x0
  95.         $aRet = DllCall($dll, "int", "GetClassNameW", "hwnd", $hFirst, "wstr", "", "int", 4096)
  96.         If $aRet[2] = 'msctls_trackbar32' Then
  97.             $aHWnd[0][0] = $hFirst
  98.             $aRet = DllCall($dll, "int", "SendMessageW", "hwnd", $hFirst, "uint", 0x400, "wparam", 0, "lparam", 0)
  99.             $aHWnd[0][1] = 100 - $aRet[0]
  100.         EndIf
  101.         $aRet = DllCall($dll, "hwnd", "GetWindow", "hwnd", $hFirst, "uint", 2)
  102.         $hFirst = $aRet[0]
  103.     WEnd
  104.     If $_sApp = '' Then
  105.         ProcessClose($iPID)
  106.         DllClose($dll)
  107.         Return $aHWnd[0][1]
  108.     EndIf
  109.     $hTmp = __Get_hTmp($dll, $hSoundMixer)
  110.     While $hTmp <> 0x0
  111.         If $aHWnd[UBound($aHWnd)-1][0] <> 0 Then ReDim $aHWnd[UBound($aHWnd)+1][2]
  112.         $aHWnd[UBound($aHWnd)-1][0] = $hTmp
  113.         $aRet = DllCall($dll, "hwnd", "GetWindow", "hwnd", $hTmp, "uint", 2)
  114.         $hTmp = $aRet[0]
  115.         $i += 1
  116.     WEnd
  117.     For $i = 1 To UBound($aHWnd)-1
  118.         $aRet = DllCall($dll, "hwnd", "GetWindow", "hwnd", $aHWnd[$i][0], "uint", 5)
  119.         $hSub = $aRet[0]
  120.         $n = 0
  121.         While $hSub <> 0x0
  122.             $n += 1
  123.             If $n = 3 Then
  124.                 $aRet = DllCall($dll, "int", "GetWindowTextW", "hwnd", $hSub, "wstr", "", "int", 4096)
  125.                 $sText = $aRet[2]
  126.             ElseIf $n = 5 Then
  127.                 $aHWnd[$i][0] = $sText
  128.                 $aRet = DllCall($dll, "int", "SendMessageW", "hwnd", $hSub, "uint", 0x400, "wparam", 0, "lparam", 0)
  129.                 $aHWnd[$i][1] = 100 - $aRet[0]
  130.                 ExitLoop
  131.             EndIf
  132.             $aRet = DllCall($dll, "hwnd", "GetWindow", "hwnd", $hSub, "uint", 2)
  133.             $hSub = $aRet[0]
  134.         WEnd
  135.     Next
  136.     DllClose($dll)
  137.     For $i = 1 To UBound($aHWnd)-1
  138.         If StringInStr($aHWnd[$i][0], $_sApp) Then
  139.             ProcessClose($iPID)
  140.             Return $aHWnd[$i][1]
  141.         EndIf
  142.     Next
  143.     ProcessClose($iPID)
  144.     Return SetError(1,0,-1)
  145. EndFunc  ;==>_Win7_SoundGetApp
  146.  
  147. ;===============================================================================
  148. ; Function Name....: _Win7_SoundSetApp
  149. ; Description......: Setzt den aktuellen Sound-Wert für eine Anwendung od. Mastervolume
  150. ; Parameter(s).....: $_iValue  zu setzender linearer Wert des Sound-Sliders
  151. ; .................: $_sApp    Name der Anwendung, Leerstring (Standard) setzt Mastervolume
  152. ; Requirement(s)...: OS Vista oder höher
  153. ; Return Value(s)..: nichts
  154. ; Author(s)........: BugFix ( bugfix@autoit.de )
  155. ;===============================================================================
  156. Func _Win7_SoundSetApp($_iValue, $_sApp='')
  157.     Local $aRet, $dll = DllOpen('user32.dll')
  158.     Local $iPID = Run("sndvol", '', @SW_MINIMIZE)
  159.     Local $oldOpt = Opt("WinTitleMatchMode", 2)
  160.     Local $hSoundMixer = WinWaitActive("Lautstärkemixer")
  161.     Opt("WinTitleMatchMode", $oldOpt)
  162.     Local $aHWnd[1][2]
  163.     $aRet = DllCall($dll, "hwnd", "GetWindow", "hwnd", $hSoundMixer, "uint", 5)
  164.     Local $hChildMix = $aRet[0]
  165.     Local $hFirst = $hChildMix, $hAppsOuter, $hAppsInner, $hTmp, $hSub, $n = 0, $i = 0, $sText
  166.     While $hFirst <> 0x0
  167.         $aRet = DllCall($dll, "int", "GetClassNameW", "hwnd", $hFirst, "wstr", "", "int", 4096)
  168.         If $aRet[2] = 'msctls_trackbar32' Then
  169.             $aHWnd[0][0] = $hFirst
  170.             If $_sApp = '' Then
  171.                 DllCall($dll, "int", "SendMessageW", "hwnd", $hFirst, "uint", 0x405, "wparam", 1, "lparam", 100 - $_iValue)
  172.                 DllClose($dll)
  173.                 Return ProcessClose($iPID)
  174.             EndIf
  175.         EndIf
  176.         $aRet = DllCall($dll, "hwnd", "GetWindow", "hwnd", $hFirst, "uint", 2)
  177.         $hFirst = $aRet[0]
  178.     WEnd
  179.     $hTmp = __Get_hTmp($dll, $hSoundMixer)
  180.     While $hTmp <> 0x0
  181.         If $aHWnd[UBound($aHWnd)-1][0] <> 0 Then ReDim $aHWnd[UBound($aHWnd)+1][2]
  182.         $aHWnd[UBound($aHWnd)-1][0] = $hTmp
  183.         $aRet = DllCall($dll, "hwnd", "GetWindow", "hwnd", $hTmp, "uint", 2)
  184.         $hTmp = $aRet[0]
  185.         $i += 1
  186.     WEnd
  187.     For $i = 1 To UBound($aHWnd)-1
  188.         $aRet = DllCall($dll, "hwnd", "GetWindow", "hwnd", $aHWnd[$i][0], "uint", 5)
  189.         $hSub = $aRet[0]
  190.         $n = 0
  191.         While $hSub <> 0x0
  192.             $n += 1
  193.             If $n = 3 Then
  194.                 $aRet = DllCall($dll, "int", "GetWindowTextW", "hwnd", $hSub, "wstr", "", "int", 4096)
  195.                 $sText = $aRet[2]
  196.             ElseIf $n = 5 Then
  197.                 $aHWnd[$i][0] = $hSub
  198.                 $aHWnd[$i][1] = $sText
  199.                 ExitLoop
  200.             EndIf
  201.             $aRet = DllCall($dll, "hwnd", "GetWindow", "hwnd", $hSub, "uint", 2)
  202.             $hSub = $aRet[0]
  203.         WEnd
  204.     Next
  205.     For $i = 1 To UBound($aHWnd)-1
  206.         If StringInStr($aHWnd[$i][1], $_sApp) Then
  207.             DllCall($dll, "int", "SendMessageW", "hwnd", $aHWnd[$i][0], "uint", 0x405, "wparam", 1, "lparam", 100 - $_iValue)
  208.             DllClose($dll)
  209.             Return ProcessClose($iPID)
  210.         EndIf
  211.     Next
  212. EndFunc  ;==>_Win7_SoundSetApp
  213.  
  214. Func __Get_hTmp(ByRef $dll, $_hSoundMixer)
  215.     Local $aRet
  216.     $aRet = DllCall($dll, "hwnd", "GetWindow", "hwnd", $_hSoundMixer, "uint", 5)
  217.     $aRet = DllCall($dll, "hwnd", "GetWindow", "hwnd", $aRet[0], "uint", 2)
  218.     $aRet = DllCall($dll, "hwnd", "GetWindow", "hwnd", $aRet[0], "uint", 5)
  219.     $aRet = DllCall($dll, "hwnd", "GetWindow", "hwnd", $aRet[0], "uint", 5)
  220.     Return $aRet[0]
  221. EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement