Jump to content

Spotify Windows 11 taskbar info bar


Recommended Posts

Hi
I made a program which get the artist – title information from the Windows Spotify program and shows it on the Windows taskbar (not working from the web version).
It’s shows the Artist – Title information on the right side on the Windows taskbar.
You can change the text colour by clicking on the icon in the icon in the systray.

image.png.ffb08dab1312bd35151be2533a9d478f.png


Can you give me feedback please?

Thanks for testing it.

Only for Windows 11 !!!!

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPISysWin.au3>
#include <Array.au3>
#include <Include/StringSize.au3>
#include <TrayConstants.au3>
#include <String.au3>
#include <Misc.au3>

Opt("TrayMenuMode", 3)

Global $program_name = "Spotibar"
Global $program_version = "V0.1"

Global $hGraphic_object_controls, $Hbitmap_controls, $nowplaying
Global $strip_extra
Local $tmr_loop = TimerInit()

_GDIPlus_Startup()

TraySetToolTip($program_name & " " & $program_version)

Local $tray_config_menu = TrayCreateMenu("Config")
Local $tray_config_strip = TrayCreateItem("Strip extra information", $tray_config_menu)
Local $tray_config_colour = TrayCreateItem("Text colour", $tray_config_menu)
Local $tray_config_autostart = TrayCreateItem("Auto start with Windows", $tray_config_menu)
TrayCreateItem("")
Local $tray_exit = TrayCreateItem("Exit")

If RegRead("HKEY_CURRENT_USER\SOFTWARE\Nend Software\Spotibar\Config", "Strip") = "" Or RegRead("HKEY_CURRENT_USER\SOFTWARE\Nend Software\Spotibar\Config", "Strip") = "1" Then
    TrayItemSetState($tray_config_strip, $TRAY_CHECKED)
    $strip_extra = True
Else
    TrayItemSetState($tray_config_strip, $TRAY_UNCHECKED)
    $strip_extra = False
EndIf

If RegRead("HKEY_CURRENT_USER\SOFTWARE\Nend Software\Spotibar\Config", "Text_colour") = "" Then
    Global $text_colour = "0xFF009B00"
Else
    Global $text_colour = "0xFF" & StringRight(RegRead("HKEY_CURRENT_USER\SOFTWARE\Nend Software\Spotibar\Config", "Text_colour"), 6)
EndIf

$var = RegRead("HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", "Spotibar")
If Not @error Then
    TrayItemSetState($tray_config_autostart, $GUI_CHECKED)
EndIf

Local $h_win_infobar = _Infobar_start()

While 1
    Local $tray = TrayGetMsg()

    Switch $tray
        Case $tray_config_strip
            If BitAND(TrayItemGetState($tray_config_strip), $TRAY_UNCHECKED) Then
                TrayItemSetState($tray_config_strip, $TRAY_CHECKED)
                RegWrite("HKEY_CURRENT_USER\SOFTWARE\Nend Software\Spotibar\Config", "Strip", "REG_SZ", 1)
                $strip_extra = True
            Else
                TrayItemSetState($tray_config_strip, $TRAY_UNCHECKED)
                RegWrite("HKEY_CURRENT_USER\SOFTWARE\Nend Software\Spotibar\Config", "Strip", "REG_SZ", 0)
                $strip_extra = False
            EndIf
        Case $tray_config_colour
            TrayItemSetState($tray_config_colour, $TRAY_CHECKED)
            Local $colourinfo = RegRead("HKEY_CURRENT_USER\SOFTWARE\Nend Software\Spotibar\Config", "Text_colour")
            If $colourinfo = "" Then
                $colourinfo = "0x009B00"
            EndIf
            $colourinfo = _ChooseColor(2, $colourinfo, 2)
            If Not (@error) Then
                If $colourinfo > "" Then
                    RegWrite("HKEY_CURRENT_USER\SOFTWARE\Nend Software\Spotibar\Config", "Text_colour", "REG_SZ", $colourinfo)
                    $text_colour = "0xFF" & StringRight($colourinfo, 6)
                    _Infobar_set_text($h_win_infobar)
                EndIf
            EndIf
            TrayItemSetState($tray_config_colour, $TRAY_UNCHECKED)
        Case $tray_config_autostart
            If BitAND(TrayItemGetState($tray_config_autostart), $TRAY_UNCHECKED) Then
                RegDelete("HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", "Spotibar")
                RegWrite("HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", "Spotibar", "REG_SZ", '"' & @ScriptDir & '\Spotibar.exe"')
                TrayItemSetState($tray_config_autostart, $TRAY_CHECKED)
            Else
                RegDelete("HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run", "Spotibar")
                TrayItemSetState($tray_config_autostart, $TRAY_UNCHECKED)
            EndIf
        Case $tray_exit
            _GDIPlus_Shutdown()
            Exit
    EndSwitch

    If TimerDiff($tmr_loop) > 1000 Then
        _TMR_get_title()
        $tmr_loop = TimerInit()
    EndIf

    Sleep(10)
WEnd

Func _TMR_get_title()
    Local Static $nowplaying_old

    $nowplaying = _Get_NowPlaying()

    If $nowplaying = "0" Then
        $nowplaying = ""
    EndIf

    If $strip_extra Then
        $nowplaying = StringRegExpReplace($nowplaying, "\([^)]*\)|\[[^)]*\]", "", 0); strip everything between ( ) and [ ]
        $nowplaying = StringStripWS($nowplaying, 3); strip leading and trealing whitespace

        Local $array_strip = StringRegExp($nowplaying, "(.*?\s-\s.*?)\s-\s.*", $STR_REGEXPARRAYGLOBALMATCH, 1); strip everything after the second dash character
        If Not @error Then
            $nowplaying = $array_strip[0]
        EndIf
    EndIf

    If $nowplaying <> $nowplaying_old Then
        TraySetToolTip($program_name & " " & $program_version & @CRLF & @CRLF & $nowplaying)

        ConsoleWrite($nowplaying & @CRLF)

        _Infobar_set_text($h_win_infobar)
        $nowplaying_old = $nowplaying
    EndIf
    _Infobar_Calc_Position($h_win_infobar)
    WinSetOnTop($h_win_infobar, "", 1)
EndFunc

Func _Get_NowPlaying()
    Local $aWinLis

    For $i = 0 To 15
        $aWinList = WinList("[Class:Chrome_WidgetWin_0; INSTANCE:" & $i & "]")
        If UBound($aWinList) > 1 Then
            If $aWinList[1][0] > "" Then
                Return $aWinList[1][0]
                ExitLoop
            EndIf
        EndIf
    Next
EndFunc

Func _Infobar_start()
    $Hbitmap_controls = _GDIPlus_BitmapCreateFromScan0(800, 25)
    $hGraphic_object_controls = _GDIPlus_ImageGetGraphicsContext($Hbitmap_controls)

    _GDIPlus_GraphicsSetTextRenderingHint($hGraphic_object_controls, 4)
    _GDIPlus_GraphicsSetSmoothingMode($hGraphic_object_controls, $GDIP_SMOOTHINGMODE_HIGHQUALITY) ;Sets the graphics object rendering quality (antialiasing)

    Local $fullscreencontrolgui = GUICreate("", 0, 0, 0, 0, $WS_POPUP, BitOR($WS_EX_LAYERED,$WS_EX_TOOLWINDOW))

    _SetBitmap($fullscreencontrolgui, $Hbitmap_controls, 255, 1000, 25)
    GUISetState(@SW_SHOW, $fullscreencontrolgui)
    WinSetOnTop($fullscreencontrolgui, "", 1)

    Return $fullscreencontrolgui
EndFunc

Func _Infobar_set_text($h_win)
    Local Static $pos_array[2]

    If NOT _Infobar_visible() Then
        $nowplaying = ""
    EndIf

    For $i = 255 To 0 Step -15
        _SetBitmap($h_win, $Hbitmap_controls, $i, $pos_array[0], $pos_array[1])
        Sleep(7)
    Next

    _GDIPlus_GraphicsClear($hGraphic_object_controls, 0x00000000)

    Local $hBrush = _GDIPlus_BrushCreateSolid($text_colour)

    Local $hFormat = _GDIPlus_StringFormatCreate()
    Local $hFamily = _GDIPlus_FontFamilyCreate("Segoe UI")
    Local $hFont = _GDIPlus_FontCreate($hFamily, 12, 1)
    Local $tLayout = _GDIPlus_RectFCreate(0, 0, 1000, 100)

    _GDIPlus_GraphicsDrawStringEx($hGraphic_object_controls, $nowplaying, $hFont, $tLayout, $hFormat, $hBrush)

    _GDIPlus_BrushDispose($hBrush)
    _GDIPlus_StringFormatDispose($hFormat)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_FontDispose($hFont)

    Local $a_pos = ControlGetPos("[CLASS:Shell_TrayWnd]", "", "Windows.UI.Composition.DesktopWindowContentBridge1")
    If Not @error Then
        Local $a_info = _StringSize($nowplaying, 12, 600, 0, "Segoe UI")

        $pos_array[0] = $a_info[2]
        $pos_array[1] = $a_info[3]

        WinMove($h_win, "", ($a_pos[0] - $a_info[2]) - 10, @DesktopHeight - ($a_pos[3] / 2) - 12, $a_info[2] + 20, $a_info[3])

        For $i = 0 To 255 Step 15
            _SetBitmap($h_win, $Hbitmap_controls, $i, $a_info[2], $a_info[3])
            Sleep(7)
        Next

        _SetBitmap($h_win, $Hbitmap_controls, 255, $a_info[2], $a_info[3])

        _Infobar_Calc_Position($h_win_infobar)
    EndIf
EndFunc

Func _Infobar_Calc_Position($h_win)
    Local Static $nowplaying_len, $start_cord_check_old

    If NOT _Infobar_visible() Then
        $nowplaying = ""
    EndIf

    Local $a_pos = ControlGetPos("[CLASS:Shell_TrayWnd]", "", "Windows.UI.Composition.DesktopWindowContentBridge1")
    If Not @error Then
        Local $a_info = _StringSize($nowplaying, 12, 600, 0, "Segoe UI")

        If Stringlen($nowplaying) <> $nowplaying_len Then
            _SetBitmap($h_win, $Hbitmap_controls, 255, $a_info[2] + 20, $a_info[3])
            $nowplaying_len = Stringlen($nowplaying)
        EndIf
        Local $start_cord_check = ($a_pos[0] - $a_info[2]) - 10
        If ($a_pos[0] - $a_info[2]) - 15 <> $start_cord_check_old Then
            WinMove($h_win, "", $start_cord_check, (@DesktopHeight - ($a_pos[3] / 2)) - 12, $a_info[2] + 20, $a_info[3])
            $start_cord_check_old = $start_cord_check
        EndIf
    EndIf
EndFunc

Func _Infobar_visible()
    If WinActive("[CLASS:WorkerW]") Or WinActive("[CLASS:Progman]") Then
        Return True
    Else
        Local $aPos = WinGetPos("[ACTIVE]")
        If Not @error Then
            If IsArray($aPos) Then
                If UBound($aPos) < 5 Then
                    If $aPos[2] >= @DesktopWidth And $aPos[3] >= @DesktopHeight Then
                        Return False
                    Else
                        Return True
                    EndIf
                EndIf
            Else
                Return True
            EndIf
            SetError(1)
        EndIf
    EndIf
EndFunc

Func _SetBitmap($hGUI, $hImage, $iOpacity, $n_width = 200, $n_height = 200)
    Local $hScrDC, $hMemDC, $hBitmap, $hOld, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend

    $hScrDC = _WinAPI_GetDC(0)
    $hMemDC = _WinAPI_CreateCompatibleDC($hScrDC)
    $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
    $hOld = _WinAPI_SelectObject($hMemDC, $hBitmap)
    $tSize = DllStructCreate($tagSIZE)
    $pSize = DllStructGetPtr($tSize)
    DllStructSetData($tSize, "X", $n_width)
    DllStructSetData($tSize, "Y", $n_height)
    $tSource = DllStructCreate($tagPOINT)
    $pSource = DllStructGetPtr($tSource)
    $tBlend = DllStructCreate($tagBLENDFUNCTION)
    $pBlend = DllStructGetPtr($tBlend)
    DllStructSetData($tBlend, "Alpha", $iOpacity)
    DllStructSetData($tBlend, "Format", 1)
    _WinAPI_UpdateLayeredWindow($hGUI, $hScrDC, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, 2)
    _WinAPI_ReleaseDC(0, $hScrDC)
    _WinAPI_SelectObject($hMemDC, $hOld)
    _WinAPI_DeleteObject($hBitmap)
    _WinAPI_DeleteDC($hMemDC)
EndFunc

 

Edited by nend
Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...