Sign in to follow this  
Followers 0
Mechaflash

Ticker (stocks, news, etc)

11 posts in this topic

#1 ·  Posted (edited)

Below is some code I created to make a ticker. It's a full, working example, so feel free to just plug it in and go. I'll be making it into a formal UDF. Thought I'd throw it up here for people to scrutinize in case some may find ways to shorten the code or ways to make it more flexible.

#include <GUIConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Local $array[5] = ["Ticker entry 1", "Ticker entry 2", "Ticker entry 3", "Ticker Entry 4", "Ticker Entry 5"]
Local $array2[5] = ["Ticker entry 6", "Ticker entry 7", "Ticker entry 8", "Ticker Entry 9", "Ticker Entry 10"]

$hGUI = GUICreate("Ticker Demo", 800, 80, Default, Default, Default, $WS_EX_COMPOSITED)

_Ticker_Initialize()
_Ticker_Create($array, 0, 20, 1200, 20, $hGUI)
_Ticker_Create($array2, 0, 50, 400, 20, $hGUI)
_Ticker_Set_Speed(5)
GUISetState()

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd


Func _Ticker_Initialize()
    Global $_Ticker_Handles[2], $_Ticker_Info_Array[2], $_Ticker_Separator, $_Ticker_Space, $_Ticker_Speed[2]
EndFunc

Func _Ticker_Create(Const $_Ticker_Info_Input, Const $_Ticker_Left, Const $_Ticker_Top, Const $_Ticker_Width, Const $_Ticker_Height, Const $_Ticker_GUI_Handle = "[LAST]")
    Static Global $_Ticker_Enumerator = 0
    Local $i = 0, $_Ticker_Append_Count

    $_Ticker_Enumerator+=1
    $_Ticker_Handles[0] = $_Ticker_Enumerator
    $_Ticker_Info_Array[0] = $_Ticker_Enumerator

    ReDim $_Ticker_Handles[$_Ticker_Enumerator + 1]
    ReDim $_Ticker_Info_Array[$_Ticker_Enumerator + 1]

    $_Ticker_Separator = "          |          "
    $_Ticker_Space = "          "

    For $value in $_Ticker_Info_Input
        If Not $i Then
            $i = 1
            $_Ticker_Info_Array[$_Ticker_Enumerator] = $value
        Else
            $_Ticker_Info_Array[$_Ticker_Enumerator]&=$_Ticker_Space & $value
        EndIf
    Next

    $_Ticker_Append_Count = Int(Ceiling($_Ticker_Width / StringLen($_Ticker_Info_Array[$_Ticker_Enumerator]) / 3) + 1)

    For $i = 1 To $_Ticker_Append_Count
        $_Ticker_Info_Array[$_Ticker_Enumerator]&=$_Ticker_Separator & $_Ticker_Info_Array[$_Ticker_Enumerator]
    Next

    $_Ticker_Info_Array[$_Ticker_Enumerator]&=$_Ticker_Separator & $_Ticker_Info_Array[$_Ticker_Enumerator]

    $_Ticker_Handle = GUICtrlCreateLabel($_Ticker_Info_Array[$_Ticker_Enumerator], $_Ticker_Left, $_Ticker_Top, $_Ticker_Width, $_Ticker_Height, BitOR($SS_LEFTNOWORDWRAP, $SS_SUNKEN))
    $_Ticker_Handles[$_Ticker_Enumerator] = $_Ticker_Handle

    _Ticker_Set_Speed()

    Return $_Ticker_Handle
EndFunc

Func _Ticker_Set_Speed(Const $_Ticker_Speed = 3)
    Switch Int($_Ticker_Speed)
        Case 1
            $_Ticker_Insert_Speed = 2000
        Case 2
            $_Ticker_Insert_Speed = 1000
        Case 3
            $_Ticker_Insert_Speed = 500
        Case 4
            $_Ticker_Insert_Speed = 200
        Case 5
            $_Ticker_Insert_Speed = 100
        Case Else
            msgbox(64 + 262144, @ScriptName, "Bad argument for _Ticker_Create() $_Ticker_Speed variable." & @LF & "Range must be between 1 - slowest to 5 - fastest.")
            Exit 0
    EndSwitch

    AdlibRegister("_Ticker_Movement", $_Ticker_Insert_Speed)
EndFunc

Func _Ticker_Movement()
    Local $_Ticker_Update, $_Ticker_ID
    For $_Ticker_ID = 1 To $_Ticker_Handles[0]
        GUICtrlSetData($_Ticker_Handles[$_Ticker_ID], StringTrimLeft(GUICtrlRead($_Ticker_Handles[$_Ticker_ID]), 3))
        If StringLen(GUICtrlRead($_Ticker_Handles[$_Ticker_ID])) <= StringLen($_Ticker_Handles[$_Ticker_ID]) Then
            $_Ticker_Update = GUICtrlRead($_Ticker_Handles[$_Ticker_ID]) & $_Ticker_Separator & $_Ticker_Info_Array[$_Ticker_ID]
            GUICtrlSetData($_Ticker_Handles[$_Ticker_ID], $_Ticker_Update)
        EndIf
    Next
EndFunc

Edited by mechaflash213

Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Share this post


Link to post
Share on other sites



Some pretty heavy flicker (win7x86). Here is a link to a GDI ticker that is a bit smoother on draw if you are hunting for other ways.


,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

@mechaflash213

The board kinda hosed your code (added a bunch of &amp; in there). But you can also fix the flicker with a simple extended style on your GUI:

$hGUI = GUICreate("Ticker Demo", 800, 80, Default, Default, Default, $WS_EX_COMPOSITED)

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

GAH STUPID EDIT!

Sorry about the W7 flicker. Tested on XP and didn't see the flicker. I'll change the code to show the style $WS_EX_COMPOSITED

EDIT: Changes made to code. Added the necessary #include for the window style and fixed all the &amp; from a previous edit =/

Edited by mechaflash213

Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Share this post


Link to post
Share on other sites

Some pretty heavy flicker (win7x86). Here is a link to a GDI ticker that is a bit smoother on draw if you are hunting for other ways.

Hmm... would you see any difference between using the GDI Draw method as opposed to the label method used?


Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Share this post


Link to post
Share on other sites

Your edit for the GUI style is wrong. It needs to be exactly my line, as WS_EX_COMPOSITED is an extended style.

Share this post


Link to post
Share on other sites

Your edit for the GUI style is wrong. It needs to be exactly my line, as WS_EX_COMPOSITED is an extended style.

Fixed =/. My eyes were playing tricks on me.


Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Share this post


Link to post
Share on other sites

would you see any difference between using the GDI Draw method as opposed to the label method used?

With GDI threads there is always the chance that UEZ will jump in and make your project all sexy.


,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

With GDI threads there is always the chance that UEZ will jump in and make your project all sexy.

Have a look here:

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

wow... using GDI makes it look uber sexy ;)

you mind if I use that function to make alterations to mine?

I'm looking to keep the syntax similar to using a label, and making the entire process self-contained.

I'm removing the need for the user to initialize the ticker, and instead run a routine to check if initialization has been run in the first instance of a _Ticker_Create(), and if not, run the initialization. This will simplify building the ticker.

I'm also going to make the ticker information actively updateable. Being able to change ticker information in the middle of scrolling.

Since _Ticker_Create() returns the handle to the label, you would utilize GUICtrlSetData() to change the value, set event for if the data changes to save the new value, trim it to where it left off at and continue on.

I'll add some arguments to include font size, weight, and style as well.

What do you think about the above mentioned features?


Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Share this post


Link to post
Share on other sites

Go ahead and show us the result!

Btw, it is GDI+ and not GDI...

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

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