Jump to content

Make Text Scroll to the Left if Longer Than GUI Box


Recommended Posts

I'm making a simple GUI that will stay on top of all my other windows that will work with the Billy MP3 Player.

Basically it's just going to have play/pause, next track, previous track, and a focus button (to bring billy to the front).

But I also want it to display the current song, but some of the song titles are longer than the GUI that I'm making. Is there a way to have the text scroll left/right like it does on players like iTunes when the text is too long to display in the window?

Link to comment
Share on other sites

Something like this works, but it's a little glitchy. and the function prettymuch kills response time...

#include <GUIConstants.au3>
Opt('GuiOnEventMode',1)


$LabelText = "This is a really long text line that doesn't fit within the window."
$GUI = GUICreate("ScrollTest", 200, 200)
GUISetOnEvent($GUI_EVENT_CLOSE, "Quit")
$Label = GUICtrlCreateLabel($LabelText, 0, 0)
$Button = GUICtrlCreateButton("Response Check", 50, 80, 100, 40)
GUICtrlSetOnEvent(-1, "Response")
GUISetState(@SW_SHOW)


While 1
    ScrollLabel($Label,$Gui) ;Left
    ;ScrollLabel($Label,$Gui,"",1) Right
WEnd

Func Quit()
    Exit
EndFunc

Func Response()
    MsgBox(0,"", "A Response!")
EndFunc

Func ScrollLabel($Ctrl, $Window, $Text="",  $Direction=0, $Speed=5, $Delay=100)
    $Temp = ControlGetPos($Window,$Text, $Ctrl)
    $Temp2 = WinGetPos($Window, $Text)
    If @error Then
        SetError(1)
        Return 0
    EndIf
    $cX = $Temp[0]
    $cY = $Temp[1]
    $cWidth = $Temp[2]
    $wWidth = $Temp2[2]
    If Not $Direction  Then   ;Left
        ControlMove($Window,$Text, $Ctrl, $cX-$Speed, $cY)
        If $cX-$Speed <= 0-$cWidth Then
            ControlMove($Window, $Text, $Ctrl, $wWidth, $cY)
        EndIf
    Else ;Right
        ControlMove($Window,$Text, $Ctrl, $cX+$Speed, $cY)
        If $cX+$Speed >= $wWidth Then
            ControlMove($Window, $Text, $Ctrl, 0-$cWidth, $cY)
        EndIf
    EndIf
    Sleep($Delay)
EndFunc

Edit: I Imagine it would work better in GuiOnEventMode

Edit2: It definitely Does.

Edited by Paulie
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...