Created
April 26, 2025 18:00
-
-
Save EncodeTheCode/3ee4dc4d15c84b18d1b79338d964626a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'tk' | |
require 'win32api' | |
# --- Setup Win32 API --- | |
FindWindow = Win32API.new('user32', 'FindWindowA', ['P', 'P'], 'L') | |
GetWindowText = Win32API.new('user32', 'GetWindowTextA', ['L', 'P', 'I'], 'I') | |
# --- Global Variables --- | |
current_song = '' | |
scroll_text = '' | |
text_x = 800 | |
spacing = " " | |
scroll_speed = 2 | |
# --- Setup Tk window --- | |
root = TkRoot.new { | |
title "" | |
background "#00FF00" # green chroma background | |
geometry "800x100" | |
} | |
canvas = TkCanvas.new(root) { | |
width 800 | |
height 100 | |
background "#00FF00" | |
} | |
canvas.pack | |
text_item = canvas.create_text(text_x, 50, { | |
'text' => '', | |
'font' => ['Arial', 24, 'bold'], | |
'anchor' => 'w', | |
'fill' => 'white' | |
}) | |
# --- Function to Update WinAmp Song --- | |
def get_winamp_song | |
hwnd = FindWindow.call('Winamp v1.x', nil) | |
return nil if hwnd == 0 | |
buffer = "\0" * 256 | |
GetWindowText.call(hwnd, buffer, 256) | |
title = buffer.strip | |
if title.include?('-') && title.include?('Winamp') | |
title.gsub!(/ - Winamp.*/, '') | |
title = title.split('-', 2)[1].strip rescue title | |
return title | |
end | |
nil | |
end | |
# --- Scroll Text --- | |
update_song_counter = 0 | |
TkTimer.new(20, -1, proc { | |
update_song_counter += 1 | |
if update_song_counter >= 50 # every ~1 second | |
new_song = get_winamp_song | |
if new_song && new_song != current_song | |
current_song.replace(new_song) | |
scroll_text.replace(current_song + spacing) | |
canvas.itemconfigure(text_item, 'text' => scroll_text) | |
text_x = 800 | |
end | |
update_song_counter = 0 | |
end | |
# move text left | |
text_x -= scroll_speed | |
text_bbox = canvas.bbox(text_item) | |
if text_bbox && text_bbox[2] < 0 | |
text_x = 800 | |
end | |
canvas.coords(text_item, text_x, 50) | |
}).start | |
Tk.mainloop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment