Hey,
hab vor einiger Zeit einen iTunes Controller geschrieben.
Ich hab ihn mal auf die neue API upgedated und ne schöne GUI gebastelt
*Liest aktuelles Lied aus und zeigt es an
*Man kann folgendes machen:
HOME + Bild auf: Nächstes Lied
HOME + Bild runter: Voriges Lied
HOME + Ende: Pause/Play
Klick
#include <Misc.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <File.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GdiPlus.au3>
#Region ### START Koda GUI section ### Form=
Opt("WinTitleMatchMode", 4)
$pos = WinGetPos("classname=Shell_TrayWnd")
$s_gui = GUICreate("iCTRL", @DesktopWidth, 70, 0, @DesktopHeight-$pos[3]-70,$WS_POPUP,BitOR($WS_EX_TOPMOST, $ws_ex_controlparent))
$s_song = GUICtrlCreateLabel("", 90, 25)
$s_inter = GUICtrlCreateLabel("", 90, 25)
$s_album = GUICtrlCreateLabel("", 90, 25)
$s_artwork = GUICtrlCreatePic("", 0, 0,70,70)
WinSetTrans($s_gui,"",0)
GUISetBkColor(0xe1e1e1)
GUISetState(@SW_HIDE)
$file = ''
$o_file = ''
Global $k,$l,$r
#EndRegion ### END Koda GUI section ###
;~ GDI+
_GDIPlus_Startup() ;Starten
Global $hBrush = _GDIPlus_BrushCreateSolid(0xFFA4A4A4) ;Brush setzen
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($s_gui)
$iTunesApp = ObjCreate("iTunes.Application")
$Library_Tracks = $iTunesApp.LibraryPlaylist.Tracks
Global $track = "no"
AdlibRegister("_Song_Refresh",2000)
If @Error Then
TrayTip("iCTRL","Error! Code:"&@CRLF&hex(@error,8),30)
Exit
Endif
While 1
If _IsPressed("24") and _IsPressed("21") Then
$iTunesApp.NextTrack
Sleep(500)
_Song_Refresh()
EndIf
If _IsPressed("24") and _IsPressed("22") Then
$iTunesApp.PreviousTrack
Sleep(500)
_Song_Refresh()
EndIf
[/autoit] [autoit][/autoit] [autoit]If _IsPressed("24") and _IsPressed("23") Then $iTunesApp.PlayPause
WEnd
Func _FadeIn( $form = $s_gui)
For $a = 0 to 180 Step 1
Sleep(5)
WinSetTrans($form,$form,$a)
Next
EndFunc
Func _FadeOut( $form = $s_gui)
For $i = 180 to 0 step -1
Sleep(5)
WinSetTrans($form,$form,$i)
Next
GUISetState(@SW_HIDE,$s_gui)
Sleep(1000)
EndFunc
Func _Song_Refresh()
$state=$iTunesApp.PlayerState
$curtrack= $iTunesApp.CurrentTrack
;~ ConsoleWrite($state & " " & $curtrack.name & @CRLF) ;DEBUG
If $curtrack.name <> $track and $state = 1 and ProcessExists("iTunes.exe")Then
$track = $curtrack.name
GUICtrlDelete($s_artwork)
GUICtrlDelete($s_album)
GUICtrlDelete($s_inter)
GUICtrlDelete($s_song)
$s_artwork = GUICtrlCreatePic("", 0, 0,70,70)
$Album = ""
$Album = $curtrack.Album
_Write($Album)
$i = _GetTextLabelWidth($curtrack.name,"Arial",15,200)
$s_song = GUICtrlCreateLabel($curtrack.name, 90, 25,$i,25)
GUICtrlSetColor($s_song,0x2E2E2E)
GUICtrlSetFont($s_song,15,200,Default,"Arial")
GUICtrlSetData($s_song,$curtrack.name)
$hwd_song = GUICtrlGetHandle($s_song)
$pos_song = ControlGetPos($s_gui,$s_gui,$hwd_song)
ConsoleWrite("Width song: "&$pos_song[2]&@CRLF)
$s_inter = GUICtrlCreateLabel($curtrack.Artist,100+$pos_song[2],25,_GetTextLabelWidth($curtrack.Artist,"Arial",15,800),25)
GUICtrlSetColor($s_inter,0x2E2E2E)
GUICtrlSetFont($s_inter,15,800,Default,"Arial")
GUICtrlSetData($s_inter,$curtrack.Artist)
If $Album <> "" Then
$hwd_inter = GUICtrlGetHandle($s_inter)
$pos_inter = ControlGetPos($s_gui,$s_gui,$hwd_inter)
ConsoleWrite("Width interpret: "&$pos_inter[2]&@CRLF)
$s_album = GUICtrlCreateLabel($Album,120+$pos_song[2]+$pos_inter[2],25,_GetTextLabelWidth($curtrack.Album,"Arial",15,200),25)
GUICtrlSetColor($s_album,0x2E2E2E)
GUICtrlSetFont($s_album,15,200,Default,"Arial")
EndIf
_Write($Album)
;~ GUICtrlSetData($s_song,$curtrack.name & Chr(014)& $curtrack.Artist &Chr(014)& $Album)
$file = @ScriptDir & '\cover_cache_'&Random(0,900,1)&'.jpg'
$curtrack.Artwork(1).SaveArtworkToFile($file)
If FileExists($file) Then GUICtrlSetImage($s_artwork,$file)
GUISetState(@SW_SHOWNOACTIVATE,$s_gui)
;~ ConsoleWrite($file & @CRLF & $curtrack.Artwork(1).SaveArtworkToFile($file))
$k = 0
FileDelete($file)
$file = ""
Local Const $sCLSID_TaskbarList = "{56FDF344-FD6D-11D0-958A-006097C9A090}"
Local Const $sIID_ITaskbarList = "{56FDF342-FD6D-11D0-958A-006097C9A090}"
Local Const $sTagITaskbarList = "HrInit hresult(); AddTab hresult(hwnd); DeleteTab hresult(hwnd); ActivateTab hresult(hwnd); SetActiveAlt hresult(hwnd);"
Local $oTaskbarList = ObjCreateInterface($sCLSID_TaskbarList, $sIID_ITaskbarList, $sTagITaskbarList)
$oTaskbarList.HrInit()
Local $hGui = WinGetHandle($s_gui)
$oTaskbarList.DeleteTab($hGui)
_FadeIn()
$o = 0
$l = 0
$r = 0
Do
Sleep(50)
_Balk()
Until $k = 100
_WinAPI_RedrawWindow($s_gui)
_FadeOut()
EndIf
EndFunc
Func _Balk()
_WinAPI_RedrawWindow($s_gui)
$l = $r
$r = Random(0,200,1)
If Abs($l - $r) > 5 Then _GDIPlus_GraphicsFillRect($hGraphic,@DesktopWidth -$r ,0,$r,70,$hBrush)
;~ ConsoleWrite($r & "-"& $k & @CRLF)
$k = $k +1
EndFunc
Func _Write($string)
ConsoleWrite($string & @CRLF)
EndFunc
Func _GetTextLabelWidth($s_WinText, $s_TextFont, $i_FontSize, $i_FontWeight = -1)
Local Const $DEFAULT_CHARSET = 0 ; ANSI character set
Local Const $OUT_CHARACTER_PRECIS = 2
Local Const $CLIP_DEFAULT_PRECIS = 0
Local Const $PROOF_QUALITY = 2
Local Const $FIXED_PITCH = 1
Local Const $RGN_XOR = 3
Local Const $LOGPIXELSY = 90
$h_WinTitle = "Get Label Width"
If $i_FontWeight = "" Or $i_FontWeight = -1 Then $i_FontWeight = 600 ; default Font weight
Local $h_GUI = GUICreate($h_WinTitle, 10, 10, -100, -100, $WS_POPUPWINDOW, $WS_EX_TOOLWINDOW)
Local $hDC = DllCall("user32.dll", "int", "GetDC", "hwnd", $h_GUI)
Local $intDeviceCap = DllCall("gdi32.dll", "long", "GetDeviceCaps", "int", $hDC[0], "long", $LOGPIXELSY)
$intDeviceCap = $intDeviceCap[0]
Local $intFontHeight = DllCall("kernel32.dll", "long", "MulDiv", "long", $i_FontSize, "long", $intDeviceCap, "long", 72)
$intFontHeight = -$intFontHeight[0]
Local $hMyFont = DllCall("gdi32.dll", "hwnd", "CreateFont", "int", $intFontHeight, _
"int", 0, "int", 0, "int", 0, "int", $i_FontWeight, "int", 0, _
"int", 0, "int", 0, "int", $DEFAULT_CHARSET, _
"int", $OUT_CHARACTER_PRECIS, "int", $CLIP_DEFAULT_PRECIS, _
"int", $PROOF_QUALITY, "int", $FIXED_PITCH, "str", $s_TextFont)
DllCall("gdi32.dll", "hwnd", "SelectObject", "int", $hDC[0], "hwnd", $hMyFont[0])
Local $res = DllStructCreate("int;int")
[/autoit] [autoit][/autoit] [autoit]Local $ret = DllCall("gdi32.dll", "int", "GetTextExtentPoint32", "int", $hDC[0], "str", $s_WinText, "long", StringLen($s_WinText), "ptr", DllStructGetPtr($res))
[/autoit] [autoit][/autoit] [autoit]Local $intLabelWidth = DllStructGetData($res,1)
[/autoit] [autoit][/autoit] [autoit]GUIDelete($h_GUI)
Return $intLabelWidth
EndFunc
Viel Spaß!
[Blockierte Grafik: http://abload.de/img/screenshot5833s39.png]