Jump to content

Recommended Posts

Posted (edited)

There was a stock ticker thread that had an incomplete ticker example from champak. This is my implementation of that script, it performs the following:

BUG:::: When selecting only a few stocks it truncates the leftmost character on the first selection. In the Example, if you reduce the selections to just the first three, GOOG becomes "OOG" when displayed. ::::::

--First time run it will create an ini in the ScriptDir with the selections you provide, subsequent runs will just read the ini rather than ask again. Delete the ini to reselect or add additional codes there.

*a couple hundred codes are commented out at the top of the au3 if you need some to play with.

--It downloads a new CSV with your selections once a minute, so when you get over @100 selections it refreshes before you get an opportunity to view all codes (at the current speed).

--Hides your TrayWnd and draws the GUI at the bottom (Will expand/contract depending on number of selections, looks best when larger than width of the screen).

--Exits with ESC and puts your tray back.

Please offer any suggestions.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#Include <Array.au3>
#include <IE.au3>
#Include <string.au3>
#include <GuiListView.au3>
#include <WinAPI.au3>


;-----some stock codes for test-----------------
;~ GOOG,MSFT,ibm,x,f,siri,cvc,g,r,HBC,JPM,NBG,PRU,LYG,STT,MA,MET,AFL,KB,AV,SHG,CB,ACE,COF,BBT,BEN,ALL,SLF,IBN,WU,MMC,STD,BAC,WFC,GS,RY,L,RBS,DFS,PFG,ICE,NYX,SLM,MTB,MCO,
;~ BAP,WSH,PRE,CMA,AIG,AXS,NYB,AIZ,UNM,IX,FFH,LNC,RF,XL,RE,BLK,KEY,LM,GNW,HDB,AEG,PGR,AOC,HIG,STI,AMP,IVZ,BRK/A,WBK,BBV,C,MTU,UBS,BCS,CS,TD,DB,USB,AXA,BNS,MS,AXP,
;~ BRK/B,V,BK,LFC,MFC,TRV,ING,MFG,BMO,PUK,NMR,PNC,CM,
;~ TMK,WRB,EFX,RGA,EV,RNR,MKL,FNF,JEF,WF,HCC,MXB,IRE,TRH,LAZ,AIB,FII,AMG,CFR,FHN,FAF,WDR,ORI,JNS,RJF,WTM,AJG,THG,SAN,AGO,BOH,BRO,MI,AHL,VR,AFG,
;~ PJC,CSH,UTR,AF,ONB,CSE,WL,FNB,FRE,WBS,BCH,VLY,SFG,ENH,PTP,BXS,PL,PRA,AWH,CYN,Y,SF,TCB,MRH,FNM,BMA,NAL,GHL,ZNT,DFG,ACF,KBW,CNO,SNV,RLI,ITG,MCY,
;~ OCN,MF,MBI,EIG,CAN,CBU,PFS,BCA,MTG,FIF,ART,HMN,EVR,GLG,RDN,FCF,FSR,CNS,NNI,PVD,MIG,BLX,PNX,SWS,CIT,NFP,AEL,DUF,ABK,WAL,OB,FFG,OFG,MGI,OPY,AEA,
;~ BFR,SBX,SUR,WHG,KFS,CIA,SFE,FMR,PMI,STU,GBL,ASI,STC,FBP,JMP,LAB,FMD,STL,NYM,AGM,PRS,SBP,PZN,CPF,FAC,CBC,IHC,DRL,FBC,WHI,BBX
;-------------------------------------------------

Global $GUI_DOCKHORZ=$GUI_DOCKLEFT+$GUI_DOCKRIGHT
Global $GUI_DOCKMARQUEE=$GUI_DOCKHORZ+$GUI_DOCKHEIGHT

Opt("GUIOnEventMode", 1)
Opt("GUICloseOnESC", 1)
GUISetOnEvent($GUI_EVENT_CLOSE, "GUI_CLOSE")


If $GUI_EVENT_CLOSE Then
    WinSetState("[CLASS:Shell_TrayWnd]", "", @SW_SHOW)
    Endif

$CodesINIread = IniRead (@ScriptDir & "\stocks.ini" , "stocks" , "codes" ,"GOOG,MSFT,ibm,BAP,WSH,PRE,CMA,AIG,AXS,NYB,AIZ,UNM,IX,FFH,LNC")

If Not FileExists (@ScriptDir & "\stocks.ini") Then
    $Input2 = InputBox ("Which Stocks?" , "Enter the codes seperated by commas, No Spaces!  If you wish to reselect codes please delete the .ini file created in the same directory as the .exe" , $codesINIread)
    $CodesINI = IniWrite (@ScriptDir & "\stocks.ini" , "stocks" , "codes" , $Input2)
Else
    $Input2 = $CodesINIread
    Endif


Global $TickerEntries,$TickerTimer, $TickerText

GUI_SetTicker()

$codes = ubound($TickerEntries) - 1
WinSetState("[CLASS:Shell_TrayWnd]", "", @SW_HIDE)

$Form1 = GUICreate("Stock Ticker", $codes * 150, 21, 0, @DesktopHeight - 21, $WS_POPUPWINDOW)

GUISetOnEvent($GUI_EVENT_CLOSE,'GUI_Close')
$Label1 = GUICtrlCreateLabel(" Loading Ticker... Please wait.", 0, 0, $codes * 150, 21, -1, $WS_EX_STATICEDGE)
GUICtrlSetResizing(-1,$GUI_DOCKMARQUEE+$GUI_DOCKTOP)
GUICtrlSetColor(-1, 0x00FF00)
GUICtrlSetBkColor(-1, 0x000000)
GUICtrlSetResizing(-1,$GUI_DOCKLEFT+$GUI_DOCKSIZE+$GUI_DOCKTOP)


_GDIPlus_Startup()
Global $hCtrl=ControlGetHandle($Form1,'',$Label1)
Global $gro
Global $grb
Global $gr
Global $hFamily = _GDIPlus_FontFamilyCreate ("Arial")
Global $hFont = _GDIPlus_FontCreate ($hFamily, 10, 2)
Global $tLayout
Global $hFormat = _GDIPlus_StringFormatCreate ()
Global $hBrush=_GDIPlus_BrushCreateSolid(0xFF00FF00)
Global $iMove=0
Global $gr_dim[4]=[0,0,0,0]

GUISetState(@SW_SHOW)
GUI_TickerSize()
GUIRegisterMsg($WM_SIZE, "WM_SIZE")

$TickerString = _ArrayToString ($TickerEntries, "+")
$TickerStringTrim = stringtrimleft ($TickerString , 3)
$TickerStringDone = stringtrimright ($TickerStringTrim , 1)
Global $symbol = $TickerStringTrim


  Global $qf=@Scriptdir & '\yahoo_stockinfo.csv'
    InetGet('http://download.finance.yahoo.com/d/quotes.csv?s='&StringUpper($Symbol)&'+'&'&f=.csv',$qf,1,1)

While 1

    IF @SEC = 01 Then
    InetGet('http://download.finance.yahoo.com/d/quotes.csv?s='&StringUpper($Symbol)&'+'&'&f=.csv',$qf,1,1)
EndIf

    If IsArray($TickerEntries) Then

        If TimerDiff($TickerTimer)>60000 Then
            $TickerText=''
            For $i=1 To UBound($TickerEntries)-1
                If StringLen($TickerEntries[$i])<1 Then ContinueLoop
                Local $StockInfo=_Stock_GetInfo($TickerEntries[$i])
            Next

                If IsArray($StockInfo) Then
                    For $i = 3 to ubound($Stockinfo) - 3 Step 3
                    $TickerText&=$StockInfo[$i]&' '&' ('&$StockInfo[$i-1]&')  - '

                    Next
                EndIf

            $TickerTimer=TimerInit()
        Else
            GUI_DrawTicker($TickerText)
            Sleep(15)
            $iMove+=1
        EndIf
    Else
        Sleep(300)
    EndIf


WEnd


Func GUI_SetTicker()
    Global $TickerEntries, $TickerTimer, $TickerText
    $TickerTimer=0
    $TickerEntries=''
    $TickerText=''
    $TickerEntries=StringSplit($Input2 & ',' , ',')
EndFunc


Func GUI_Close()

    If InetGetInfo() Then InetGet('abort')

    $TickerTimer=0
    $TickerEntries=''
    $TickerText=''

    $tLayout=0
    If $hFamily Then _GDIPlus_FontFamilyDispose($hFamily)
    If $hFont Then _GDIPlus_FontDispose($hFont)
    If $hFormat Then _GDIPlus_StringFormatDispose($hFormat)
    If $hBrush Then _GDIPlus_BrushDispose($hBrush)
    If $gr Then _GDIPlus_GraphicsDispose($gr)
    If $grb Then _GDIPlus_BitmapDispose($grb)
    If $gro Then _GDIPlus_GraphicsDispose($gro)

    GUISetState(@SW_HIDE)
    GUIDelete($Form1)
    WinSetState("[CLASS:Shell_TrayWnd]", "", @SW_SHOW)
    Exit
EndFunc


Func GUI_TickerSize()
    Global $gro, $grb, $gr_dim
    $gr_dim=ControlGetPos($Form1,'',$Label1)
    ConsoleWrite('TickerResize '&$gr_dim[2]&@CRLF)
    Local $cgp=$gr_dim

    If $gro Then _GDIPlus_GraphicsDispose($gro)
    $gro=_GDIPlus_GraphicsCreateFromHWND($hCtrl)

    If $gr Then _GDIPlus_GraphicsDispose($gr)
    If $grb Then _GDIPlus_BitmapDispose($grb)
    $grb=_GDIPlus_BitmapCreateFromGraphics($cgp[2],$cgp[3],$gro); I'd only make one - but the darn thing has to resize!
    $gr=_GDIPlus_ImageGetGraphicsContext($grb)
EndFunc


Func GUI_DrawTicker($str)
    Global $gr_dim,$iMove
    Local $cgp=$gr_dim

    If $iMove>$cgp[2] Then
        ConsoleWrite('TickerBack '&$iMove&'>'&$cgp[2]&@CRLF)
        $iMove=0
    EndIf
    _GDIPlus_GraphicsClear($gr,0xFF000000)

    $tLayout = 0
    $tLayout = _GDIPlus_RectFCreate ($iMove,0, $cgp[2], $cgp[3])
    _GDIPlus_GraphicsDrawStringEx ($gr, $str, $hFont, $tLayout, $hFormat, $hBrush)

    $tLayout = 0
    $tLayout = _GDIPlus_RectFCreate ($iMove-$cgp[2],0, $cgp[2], $cgp[3])
    _GDIPlus_GraphicsDrawStringEx ($gr, $str, $hFont, $tLayout, $hFormat, $hBrush)

    _GDIPlus_GraphicsDrawImageRect($gro, $grb, 0, 0, $cgp[2], $cgp[3]);copy to bitmap
EndFunc


Func _Stock_GetInfo($Symbol)

    $iMove=0
    While InetGetInfo()
        GUI_DrawTicker('Loading '&$Symbol&'... Please Wait.')
        Sleep(25)
        $iMove+=1
    WEnd

    Local $StockInfo=StringSplit(StringReplace(StringStripCR(FileRead($qf)),@LF,'')&',',',')
    Local $StockInfo_Max=UBound($StockInfo)-1
    For $i=1 To $StockInfo_Max
        If StringMid($StockInfo[$i],1,1)=='"' And StringMid($StockInfo[$i],StringLen($StockInfo[$i]),1)=='"' Then
            $StockInfo[$i]=StringTrimRight(StringTrimLeft($StockInfo[$i],1),1)
        EndIf
    Next
    Return $StockInfo
EndFunc


Func WM_SIZE($hWnd, $Msg, $wParam, $lParam)
    GUI_TickerSize()
    Return $GUI_RUNDEFMSG
EndFunc
Edited by iamtheky

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

Posted

Nice work ! Posted Image

I modify it for keep my taskbar !

It can serve...

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#Include <Array.au3>
#include <IE.au3>
#Include <string.au3>
#include <GuiListView.au3>
#include <WinAPI.au3>

;-----some stock codes for test-----------------
;~ GOOG,MSFT,ibm,x,f,siri,cvc,g,r,HBC,JPM,NBG,PRU,LYG,STT,MA,MET,AFL,KB,AV,SHG,CB,ACE,COF,BBT,BEN,ALL,SLF,IBN,WU,MMC,STD,BAC,WFC,GS,RY,L,RBS,DFS,PFG,ICE,NYX,SLM,MTB,MCO,
;~ BAP,WSH,PRE,CMA,AIG,AXS,NYB,AIZ,UNM,IX,FFH,LNC,RF,XL,RE,BLK,KEY,LM,GNW,HDB,AEG,PGR,AOC,HIG,STI,AMP,IVZ,BRK/A,WBK,BBV,C,MTU,UBS,BCS,CS,TD,DB,USB,AXA,BNS,MS,AXP,
;~ BRK/B,V,BK,LFC,MFC,TRV,ING,MFG,BMO,PUK,NMR,PNC,CM,
;~ TMK,WRB,EFX,RGA,EV,RNR,MKL,FNF,JEF,WF,HCC,MXB,IRE,TRH,LAZ,AIB,FII,AMG,CFR,FHN,FAF,WDR,ORI,JNS,RJF,WTM,AJG,THG,SAN,AGO,BOH,BRO,MI,AHL,VR,AFG,
;~ PJC,CSH,UTR,AF,ONB,CSE,WL,FNB,FRE,WBS,BCH,VLY,SFG,ENH,PTP,BXS,PL,PRA,AWH,CYN,Y,SF,TCB,MRH,FNM,BMA,NAL,GHL,ZNT,DFG,ACF,KBW,CNO,SNV,RLI,ITG,MCY,
;~ OCN,MF,MBI,EIG,CAN,CBU,PFS,BCA,MTG,FIF,ART,HMN,EVR,GLG,RDN,FCF,FSR,CNS,NNI,PVD,MIG,BLX,PNX,SWS,CIT,NFP,AEL,DUF,ABK,WAL,OB,FFG,OFG,MGI,OPY,AEA,
;~ BFR,SBX,SUR,WHG,KFS,CIA,SFE,FMR,PMI,STU,GBL,ASI,STC,FBP,JMP,LAB,FMD,STL,NYM,AGM,PRS,SBP,PZN,CPF,FAC,CBC,IHC,DRL,FBC,WHI,BBX
;-------------------------------------------------

Global $GUI_DOCKHORZ=$GUI_DOCKLEFT+$GUI_DOCKRIGHT
Global $GUI_DOCKMARQUEE=$GUI_DOCKHORZ+$GUI_DOCKHEIGHT

Opt("GUIOnEventMode", 1)
Opt("GUICloseOnESC", 1)
GUISetOnEvent($GUI_EVENT_CLOSE, "GUI_CLOSE")
If $GUI_EVENT_CLOSE Then WinSetState("[CLASS:Shell_TrayWnd]", "", @SW_SHOW)
$CodesINIread = IniRead (@ScriptDir & "\stocks.ini" , "stocks" , "codes" ,"GOOG,MSFT,ibm,BAP,WSH,PRE,CMA,AIG,AXS,NYB,AIZ,UNM,IX,FFH,LNC")

If Not FileExists (@ScriptDir & "\stocks.ini") Then
    $Input2 = InputBox ("Which Stocks?" , "Enter the codes seperated by commas, No Spaces!  If you wish to reselect codes please delete the .ini file created in the same directory as the .exe" , $codesINIread)
    $CodesINI = IniWrite (@ScriptDir & "\stocks.ini" , "stocks" , "codes" , $Input2)
Else
    $Input2 = $CodesINIread
Endif

Global $TickerEntries,$TickerTimer, $TickerText
GUI_SetTicker()
$codes = ubound($TickerEntries) - 1
$Form1 = GUICreate ( "Stock Ticker", $codes * 150, 21, 0, @DesktopHeight - _GetTaskbarHeight ( )-21, $WS_POPUPWINDOW )
GUISetOnEvent($GUI_EVENT_CLOSE,'GUI_Close')
$Label1 = GUICtrlCreateLabel(" Loading Ticker... Please wait.", 0, 0, $codes * 150, 21, -1, $WS_EX_STATICEDGE)
GUICtrlSetResizing(-1,$GUI_DOCKMARQUEE+$GUI_DOCKTOP)
GUICtrlSetColor(-1, 0x00FF00)
GUICtrlSetBkColor(-1, 0x000000)
GUICtrlSetResizing(-1,$GUI_DOCKLEFT+$GUI_DOCKSIZE+$GUI_DOCKTOP)
_GDIPlus_Startup()
Global $hCtrl=ControlGetHandle($Form1,'',$Label1)
Global $gro
Global $grb
Global $gr
Global $hFamily = _GDIPlus_FontFamilyCreate ("Arial")
Global $hFont = _GDIPlus_FontCreate ($hFamily, 10, 2)
Global $tLayout
Global $hFormat = _GDIPlus_StringFormatCreate ()
Global $hBrush=_GDIPlus_BrushCreateSolid(0xFF00FF00)
Global $iMove=0
Global $gr_dim[4]=[0,0,0,0]
GUISetState(@SW_SHOW)
GUI_TickerSize()
GUIRegisterMsg($WM_SIZE, "WM_SIZE")
$TickerString = _ArrayToString ($TickerEntries, "+")
$TickerStringTrim = stringtrimleft ($TickerString , 3)
$TickerStringDone = stringtrimright ($TickerStringTrim , 1)
Global $symbol = $TickerStringTrim
Global $qf=@Scriptdir & '\yahoo_stockinfo.csv'
InetGet('http://download.finance.yahoo.com/d/quotes.csv?s='&StringUpper($Symbol)&'+'&'&f=.csv',$qf,1,1)

While 1
    IF @SEC = 01 Then InetGet('http://download.finance.yahoo.com/d/quotes.csv?s='&StringUpper($Symbol)&'+'&'&f=.csv',$qf,1,1)
    If IsArray($TickerEntries) Then
        If TimerDiff($TickerTimer)>60000 Then
            $TickerText=''
            For $i=1 To UBound($TickerEntries)-1
                If StringLen($TickerEntries[$i])<1 Then ContinueLoop
                Local $StockInfo=_Stock_GetInfo($TickerEntries[$i])
            Next
                If IsArray($StockInfo) Then
                    For $i = 3 to ubound($Stockinfo) - 3 Step 3
                    $TickerText&=$StockInfo[$i]&' '&' ('&$StockInfo[$i-1]&')  - '
                    Next
                EndIf
            $TickerTimer=TimerInit()
        Else
            GUI_DrawTicker($TickerText)
            Sleep(15)
            $iMove+=1
        EndIf
    Else
        Sleep(300)
    EndIf
WEnd

Func GUI_SetTicker()
    Global $TickerEntries, $TickerTimer, $TickerText
    $TickerTimer=0
    $TickerEntries=''
    $TickerText=''
    $TickerEntries=StringSplit($Input2 & ',' , ',')
EndFunc

Func GUI_Close()
    If InetGetInfo() Then InetGet('abort')
    $TickerTimer=0
    $TickerEntries=''
    $TickerText=''
    $tLayout=0
    If $hFamily Then _GDIPlus_FontFamilyDispose($hFamily)
    If $hFont Then _GDIPlus_FontDispose($hFont)
    If $hFormat Then _GDIPlus_StringFormatDispose($hFormat)
    If $hBrush Then _GDIPlus_BrushDispose($hBrush)
    If $gr Then _GDIPlus_GraphicsDispose($gr)
    If $grb Then _GDIPlus_BitmapDispose($grb)
    If $gro Then _GDIPlus_GraphicsDispose($gro)
    GUISetState(@SW_HIDE)
    GUIDelete($Form1)
    WinSetState("[CLASS:Shell_TrayWnd]", "", @SW_SHOW)
    Exit
EndFunc

Func GUI_TickerSize()
    Global $gro, $grb, $gr_dim
    $gr_dim=ControlGetPos($Form1,'',$Label1)
    ConsoleWrite('TickerResize '&$gr_dim[2]&@CRLF)
    Local $cgp=$gr_dim
    If $gro Then _GDIPlus_GraphicsDispose($gro)
    $gro=_GDIPlus_GraphicsCreateFromHWND($hCtrl)
    If $gr Then _GDIPlus_GraphicsDispose($gr)
    If $grb Then _GDIPlus_BitmapDispose($grb)
    $grb=_GDIPlus_BitmapCreateFromGraphics($cgp[2],$cgp[3],$gro); I'd only make one - but the darn thing has to resize!
    $gr=_GDIPlus_ImageGetGraphicsContext($grb)
EndFunc

Func GUI_DrawTicker($str)
    Global $gr_dim,$iMove
    Local $cgp=$gr_dim
    If $iMove>$cgp[2] Then
        ConsoleWrite('TickerBack '&$iMove&'>'&$cgp[2]&@CRLF)
        $iMove=0
    EndIf
    _GDIPlus_GraphicsClear($gr,0xFF000000)
    $tLayout = 0
    $tLayout = _GDIPlus_RectFCreate ($iMove,0, $cgp[2], $cgp[3])
    _GDIPlus_GraphicsDrawStringEx ($gr, $str, $hFont, $tLayout, $hFormat, $hBrush)
    $tLayout = 0
    $tLayout = _GDIPlus_RectFCreate ($iMove-$cgp[2],0, $cgp[2], $cgp[3])
    _GDIPlus_GraphicsDrawStringEx ($gr, $str, $hFont, $tLayout, $hFormat, $hBrush)
    _GDIPlus_GraphicsDrawImageRect($gro, $grb, 0, 0, $cgp[2], $cgp[3]);copy to bitmap
EndFunc

Func _Stock_GetInfo($Symbol)
    $iMove=0
    While InetGetInfo()
        GUI_DrawTicker('Loading '&$Symbol&'... Please Wait.')
        Sleep(25)
        $iMove+=1
    WEnd
    Local $StockInfo=StringSplit(StringReplace(StringStripCR(FileRead($qf)),@LF,'')&',',',')
    Local $StockInfo_Max=UBound($StockInfo)-1
    For $i=1 To $StockInfo_Max
        If StringMid($StockInfo[$i],1,1)=='"' And StringMid($StockInfo[$i],StringLen($StockInfo[$i]),1)=='"' Then
            $StockInfo[$i]=StringTrimRight(StringTrimLeft($StockInfo[$i],1),1)
        EndIf
    Next
    Return $StockInfo
EndFunc

Func WM_SIZE($hWnd, $Msg, $wParam, $lParam)
    GUI_TickerSize()
    Return $GUI_RUNDEFMSG
EndFunc

Func _GetTaskbarHeight ( ) 
    Local Const $SPI_GETWORKAREA = 48
    Local $WorkArea, $stRect = DllStructCreate ( "long left;long top;long right;long bottom" )
    Local $iResult = _WinAPI_SystemParametersInfo ( $SPI_GETWORKAREA, 0, DllStructGetPtr ( $stRect ), 0 )
    If $iResult = True Then
        $WorkArea = DllStructGetData ( $stRect, "bottom" ) - DllStructGetData ( $stRect, "top" ) 
        If Not @error Then Return @DesktopHeight - $WorkArea
    Else    
        Return 0
    EndIf
EndFunc ;==> _GetTaskbarHeight ( )

AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

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...