Sign in to follow this  
Followers 0

Best way to create an horizontal scrolling text ?


15 posts in this topic

Posted

Hi all,

I'd like to create a simple way to diffuse some text messages at the bottom of a screen from right to left on the entire width in continue.

Goal is to diffuse message to my company's people on a 16/9 TV in a continue way. Messages would be taken from text files created in a specified directory....

How could i do this with AutoIT ?

thanks a lot for your help.

Florent

Share this post


Link to post
Share on other sites



Posted

fgilain,

Look at the Marquee UDF in my sig - should do what you want. :)

M23

Share this post


Link to post
Share on other sites

Posted (edited)

Here another example:

Simple Horizontal Label Scroller.au3 Simple Horizontal Label Scroller.au3

;coded by UEZ 2012 build 2012-03-09
#include <windowsconstants.au3>
#include "Scroller.au3"

$iW = 640
$iH = Int($iW * 9 / 16)
$hGUI = GUICreate("Simple Horizontal Scroller", $iW, $iH, -1, -1, Default, $WS_EX_COMPOSITED)
GUISetState()

$sText = "This is a simple horizontal scroller made with AutoIt using a label! Using this technique is not the best way because label is flickering :-("

$aHScroller1= Scroller_Init($hGUI, 64, $sText, "Arial", 96, 0, 0x006000, False, False, 0xABCDEF)
If @error Then Exit MsgBox(16, "ERROR", "Unable to initiate scroller", 10)

$aHScroller2= Scroller_Init($hGUI, $iH - 64, $sText, "Comic Sans MS", 24, 0, 0, True, True)
If @error Then Exit MsgBox(16, "ERROR", "Unable to initiate scroller", 10)

HotKeySet("{F1}", "Init_Scroller_Off")
HotKeySet("{F2}", "Init_Scroller_On")
HotKeySet("{F3}", "Init_Scroller_Reset")

AdlibRegister("Scroll_It", 30)

Do
Until GUIGetMsg() = -3

_Exit()

Func Scroll_It()
    Scroller_Move($aHScroller1, 1.25)
    Scroller_Move($aHScroller2, 1)
EndFunc

Func Init_Scroller_Off()
    Scroller_Off($aHScroller1[0])
EndFunc

Func Init_Scroller_On()
    Scroller_On($aHScroller1[0])
EndFunc

Func Init_Scroller_Reset()
    Scroller_Reset($aHScroller1)
EndFunc

Func _Exit()
    AdlibUnRegister("Scroll_It")
    GUIDelete($hGUI)
    Exit
EndFunc

Scroller.au3 Scroller.au3

;coded by UEZ 2012 build 2012-03-11
#include-once
#include <guiconstantsex.au3>
#include <staticconstants.au3>
#include <gdiplus.au3>

Func Scroller_Init($hGUI, $iY, $sText, $sFont = "Arial", $iFSize = 24, $iFStyle = 0, $iFColor = 0x000000, $hl = False, $bgc = False, $bgcolor = 0xFEDCBA)
    If Not IsHWnd($hGUI) Then Return SetError(1, 0, 0)
    If $sText = "" Then Return SetError(2, 0, 0)
    Local $aSize = WinGetClientSize($hGUI)
    Local $aStringSize =  GetStringSize($sText, $sFont, $iFSize, $iFStyle)
    Local $idLabel_Scroller = GUICtrlCreateLabel($sText, $aSize[0], $iY, $aStringSize[0], $aStringSize[1])
    Local $fWeight = 400
    If BitAND($iFStyle, 1) Then $fWeight = 800
    GUICtrlSetFont($idLabel_Scroller, $iFSize, $fWeight , BitXOR($iFStyle, 1), $sFont, 4)
    GUICtrlSetColor($idLabel_Scroller, $iFColor)
    If $bgc Then
        Local $idLabel_BG = GUICtrlCreateLabel("", 0, $iY - 3, $aSize[0], $aStringSize[1] + 3)
        GUICtrlSetBkColor($idLabel_BG, $bgcolor)
        GUICtrlSetState($idLabel_BG, $GUI_DISABLE)
        GUICtrlSetBkColor($idLabel_Scroller, $bgcolor)
    EndIf
    If $hl Then
        Local $idLabel_HorizontalLine1 = GUICtrlCreateLabel("", 0, $iY - 4, $aSize[0] + 4, 2, $SS_ETCHEDHORZ)
        Local $idLabel_HorizontalLine2 = GUICtrlCreateLabel("", 0, $iY + $aStringSize[1], $aSize[0] + 4, 2, $SS_ETCHEDHORZ)
    EndIf
    Local $aData[4] = [$idLabel_Scroller, $aStringSize[0], $aSize[0] + $iFSize, $aSize[0] + $iFSize] ;id label, string width, gui width, $iPos
    Return $aData
EndFunc

Func Scroller_Off($idControl)
    GUICtrlSetState($idControl, $GUI_HIDE)
EndFunc

Func Scroller_On($idControl)
    GUICtrlSetState($idControl, $GUI_SHOW)
EndFunc

Func Scroller_Reset(ByRef $aData)
    $aData[3] = $aData[2]
EndFunc

Func Scroller_Move(ByRef $aData, $iSpeed = 1)
    $aData[3] -= $iSpeed
    GUICtrlSetPos($aData[0], $aData[3])
    If $aData[3] < -$aData[1] Then $aData[3] = $aData[2]
EndFunc

Func GetStringSize($string, $font, $fontsize, $fontstyle)
    Local $GDIp = False
    Local $iWidth = StringLen($string) * $fontsize
    Local $iHeight = 2 * $fontsize
    If Not $ghGDIPDll Then
        _GDIPlus_Startup()
        $GDIp = True
    EndIf
    Local $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iWidth, "int", $iHeight, "int", 0, "int",  0x0026200A, "ptr", 0, "int*", 0)
    Local $hBitmap = $aResult[6]
    Local $hGrphContext = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    Local $hFormat = _GDIPlus_StringFormatCreate()
    Local $hFamily = _GDIPlus_FontFamilyCreate($font)
    Local $hFont = _GDIPlus_FontCreate($hFamily, $fontsize, $fontstyle)
    Local $tLayout = _GDIPlus_RectFCreate(0, 0, 0, 0)
    Local $aInfo = _GDIPlus_GraphicsMeasureString($hGrphContext, $string, $hFont, $tLayout, $hFormat)
    _GDIPlus_FontDispose($hFont)
    _GDIPlus_FontFamilyDispose($hFamily)
    _GDIPlus_StringFormatDispose($hFormat)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_GraphicsDispose($hGrphContext)
    If $GDIp Then _GDIPlus_Shutdown()
    Local $aDim[2] = [Int(DllStructGetData($aInfo[0], "Width")), Int(DllStructGetData($aInfo[0], "Height"))]
    Return $aDim
EndFunc

Br,

UEZ

Edited by UEZ

Share this post


Link to post
Share on other sites

Posted (edited)

UEZ UDF excellent, how appears only in part of the screen?

post-69288-0-51613100-1331300643_thumb.j

Edited by Belini

Share this post


Link to post
Share on other sites

Posted

Anybody else with same problem?

@Belini: Did you modify something?

Br,

UEZ

Share this post


Link to post
Share on other sites

Posted

I tried and did not work, also the font color is not changing.

Share this post


Link to post
Share on other sites

Posted

Anybody else with same problem?

@Belini: Did you modify something?

Br,

UEZ

Works for me on Windows 7 x64 using AutoIt V3.3.9.1.

Share this post


Link to post
Share on other sites

Posted

I tried it on Win 7 running both AutoIt 3.3.8.1 and 3.3.9.1, using both x64 and x86 and it worked for me.

Share this post


Link to post
Share on other sites

Posted

I cannot imagine what could be wrong with Belini's pc....

Thanks for testing!

Br,

UEZ

Share this post


Link to post
Share on other sites

Posted

I guess he's using Windows XP but no idea what service pack etc...

Share this post


Link to post
Share on other sites

Posted (edited)

I tried it on Win 7 running both AutoIt 3.3.8.1 and 3.3.9.1, using both x64 and x86 and it worked for me.

Windows XP Spack2

@ UEZ do not think you understand, I want only to appear a screen part, I do not want the whole screen

The image is an example of what I want

Edited by Belini

Share this post


Link to post
Share on other sites

Posted (edited)

The screen shot he attached was for to show you how he want it to be, he didn't said your script appears like that, he said he want it to be like that.

Edited by D4RKON3

Share this post


Link to post
Share on other sites

Posted

Sorry, I misunderstood what you want to ask!

That's not easily possible because here the whole label is moving from right to left and it cannot be implemented as shown in the screenshot.

One possibility might be creating 2 topmost child windows with appropriate size and height which overlap the left and right part of the scroller.

This could give the illusion that the scroller is only in a middle part of the gui.

Br,

UEZ

Share this post


Link to post
Share on other sites

Posted

UEZ,

I thought the same as you and probably everyone else did on the forum, that Belini had a problem with your UDF not requesting a new feature to be added.

Share this post


Link to post
Share on other sites

Posted

Thank you all for your attention, the marquee did Melba23 UDF will do what I need.

Share this post


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
Sign in to follow this  
Followers 0