Sign in to follow this  
Followers 0

_ScrollingCredits() - Create a scrolling credits control.

17 posts in this topic

Posted (edited)

I created this 'Scrolling Credits' function after I came across it gave me the idea of how to effectively embed HTML inside a control created using GUICtrlCreateObj.

Note: I've had this function laying around for about 4 months and felt it could be useful for someone. Any comments or suggestions then please post below.

The forum sometimes will remove a backslash, so I've decided to attach the file instead.

Download: _ScrollingCredits.au3

Edited by guinness
Zoldex likes this

Share this post


Link to post
Share on other sites



Posted (edited)

Nice

I use an editcontrol in combination with _GUICtrlEdit_Scroll

For example, where 35 in the amount for scolling

Func _EditScroll()
If TimerDiff($Timer_1) > 1000 Then
  $Count = $Count + 1
  If $Count < 35 Then
   _GUICtrlEdit_Scroll($Edit, $SB_LINEDOWN)
   $Timer_1 = TimerInit()
  Else
   _GUICtrlEdit_LineScroll($Edit], 0, -35)
   $Count = 0
   $Timer_1 = TimerInit()
  EndIf
EndIf
EndFunc   ;==>_EditScroll
Edited by Emiel Wieldraaijer

Share this post


Link to post
Share on other sites

Posted

OK, it's a different approach. Thanks for sharing.

Share this post


Link to post
Share on other sites

Posted

guinness,

good work!

Is it possible to make the background transparent (control overlapping)?

Greets,

-supersonic.

Share this post


Link to post
Share on other sites

Posted (edited)

supersonic,

Having spent the best part of 30 minutes thinking of an easy solution to go about this I couldn't find one. Therefore if someone else knows how then I would be interested to know the best approach. Sorry about that.

Edited by guinness

Share this post


Link to post
Share on other sites

Posted

Donno if this helps or not, not related to controls, but may give you some ideas.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIConstants.au3>
#include <GDIPlus.au3>
#include <String.au3>
#include <GuiMenu.au3>
#include <Misc.au3>

Global Const $width = 640
Global Const $height = 480
Global $graphics, $backbuffer, $bitmap, $Pen
Global $brush_color, $hFormat, $tLayout
Global $ScreenDc, $dc, $tSize, $pSize, $tSource, $pSource, $tBlend, $pBlend, $tPoint, $pPoint, $gdibitmap
Global $title = "From GDI+ Code by : UEZ!"
Global $hGUI, $hBrush
Global $iX = 0, $iY = 0, $Col, $hPen, $iWidth = 100, $iHeight =100
Global $sc_hBrush, $sc_hFormat, $sc_hFamily, $sc_hFont, $sc_text_color, $text_scroller, $sc_tLayout, $sc_pen, $sc_brush
Global $letter_distance, $x, $y, $lenght, $end, $scroller_length, $sc_k
Global $pColor = 0xFF0000F0
Global $dot_k = $Width
Global $Trans, $Size
Global Const $sc_font_size = 48


$sc_text = "#*** |||| __Transparent Text Srcoller with Clock__ |||| ***#"
Opt("GUIOnEventMode", 1)
Opt("MouseCoordMode" ,0)
$GUI= GUICreate($title, $width, $height, -1, -1, 0, $WS_EX_LAYERED + $WS_EX_TOPMOST) ;Window Must be Layered for Transparency
GUISetOnEvent($GUI_EVENT_CLOSE, "Close")
_GDIPlus_Startup()
$graphics = _GDIPlus_GraphicsCreateFromHWND($GUI)
$bitmap = _GDIPlus_BitmapCreateFromGraphics($width, $height, $graphics)
$backbuffer = _GDIPlus_ImageGetGraphicsContext($bitmap)
_GDIPlus_GraphicsSetSmoothingMode($backbuffer, 2)
$sc_hBrush = _GDIPlus_BrushCreateSolid ()
$sc_hPen = _GDIPlus_PenCreate($pColor, 1)
; == For transparency ==
$ScreenDc = _WinAPI_GetDC($GUI)
$gdibitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($bitmap)
$dc = _WinAPI_CreateCompatibleDC($ScreenDc)
_WinAPI_SelectObject($dc, $gdibitmap)
; == _WinAPI_UpdateLayeredWindow parameters ==
$tSize = DllStructCreate($tagSIZE)
$pSize = DllStructGetPtr($tSize)
DllStructSetData($tSize, "X", $width)
DllStructSetData($tSize, "Y", $height)
$tSource = DllStructCreate($tagPOINT)
$pSource = DllStructGetPtr($tSource)
$tBlend = DllStructCreate($tagBLENDFUNCTION)
$pBlend = DllStructGetPtr($tBlend)
Global $alpha = 200
Global $alpha_steps = 5
DllStructSetData($tBlend, "Alpha", $alpha)
DllStructSetData($tBlend, "Format", 1)
$tPoint = DllStructCreate($tagPOINT)
$pPoint = DllStructGetPtr($tPoint)
DllStructSetData($tPoint, "X", 0)
DllStructSetData($tPoint, "Y", 0)
;===============================================
GUISetState()
GUIRegisterMsg($WM_NCHITTEST,   "WM_NCHITTEST")  ;Drag Window
GUIRegisterMsg($WM_MOUSEWHEEL, "WM_MOUSEWHEEL")  ;Adjust Trans
;Setup Scroll Font
$sc_text_color = 0xFF6209D6
$sc_htextBrush = _GDIPlus_BrushCreateSolid($sc_text_color)
$sc_hFormat = _GDIPlus_StringFormatCreate()
$sc_hFamily = _GDIPlus_FontFamilyCreate("Arial")
$sc_hFont = _GDIPlus_FontCreate($sc_hFamily, $sc_font_size, 2)
$sc_pen = _GDIPlus_PenCreate(0)
$sc_brush = _GDIPlus_BrushCreateSolid(0)
$tLayout = _GDIPlus_RectFCreate(0, 0)
;Text Ini
$sc_letter_distance = $sc_font_size
$sc_length = $sc_font_size * 1.666 * 0.36
$sc_k = $width
$end = 0
$scroller_length = StringLen($sc_text) * $sc_length
$sc_FontY = $Height - $height/4 + 40

;Time init
  $Time_hBrush = _GDIPlus_BrushCreateSolid(0xFF008080)
  $Time_hFormat = _GDIPlus_StringFormatCreate()
  $Time_hFamily = _GDIPlus_FontFamilyCreate("Verdana")
  $Time_hFont   = _GDIPlus_FontCreate ($Time_hFamily, 48, 3)
  $Time_hLayout = _GDIPlus_RectFCreate(0, 0, $Width, 80)
 
Do
_GDIPlus_GraphicsClear($backbuffer, 0x00000000)
; This is where you do your animation/ draw stuff :-)
DrawCorners()
DrawTime()
DrawDot()
ScrollText()
;~  _GDIPlus_GraphicsDrawImageRect($graphics, $bitmap, 0, 0, $width, $height)
; This is used for the transperancy instead of _GDIPlus_GraphicsDrawImageRect
    $gdibitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($bitmap)
    _WinAPI_SelectObject($dc, $gdibitmap)
    _WinAPI_UpdateLayeredWindow($GUI, $ScreenDc, 0, $pSize, $dc, $pSource, 0, $pBlend, 2)
_WinAPI_DeleteObject($gdibitmap)
Until False * Not Sleep(30)

; Draw the digital time
Func DrawTime()
  Local $sString, $aSize
  $sString = StringFormat("%02d:%02d:%02d", @HOUR, @MIN, @SEC)
  $aSize   = _GDIPlus_GraphicsMeasureString($Backbuffer, $sString, $Time_hFont, $Time_hLayout, $Time_hFormat)
  DllStructSetData($Time_hLayout, "X", $Width/2 - (DllStructGetData($aSize[0], "Width") / 2))    ; $Width - String length/2
  DllStructSetData($Time_hLayout, "Y", 0)                        ; Clock at top
;  DllStructSetData($Time_hLayout, "Y", $Height/2 - (DllStructGetData($aSize[0], "Height") / 2))   ; Clock in middle
  _GDIPlus_GraphicsDrawStringEx($BackBuffer, $sString, $Time_hFont, $Time_hLayout, $Time_hFormat, $Time_hBrush)
EndFunc
; ================ SCROLL TEXT ====================
Func ScrollText()
$sc_FontX = $sc_k + $sc_letter_distance
DllStructSetData($tLayout, "x", $sc_FontX)
DllStructSetData($tLayout, "y", $sc_FontY)
_GDIPlus_GraphicsDrawStringEx($BackBuffer, $sc_text, $sc_hFont, $tLayout, $sc_hFormat, $sc_htextBrush)
$sc_k -= 5
If -$scroller_length >= $sc_k Then
  $sc_k = $Width
EndIf
EndFunc
; == Draw Corners ==
Func DrawCorners()
Local $Lgth = 20
$hPen1 = _GDIPlus_PenCreate(0xFF0000AA, 10)
;Top Right
      _GDIPlus_GraphicsDrawLine($backBuffer, $Width, 0, $Width - $Lgth, 0, $hPen1)
      _GDIPlus_GraphicsDrawLine($backBuffer, $Width, 0, $Width , $Lgth, $hPen1)
;Top Left
      _GDIPlus_GraphicsDrawLine($backBuffer, 0, 0, 0, $Lgth, $hPen1)
      _GDIPlus_GraphicsDrawLine($backBuffer, 0, 0, $Lgth, 0, $hPen1) 
;Bottom Right
      _GDIPlus_GraphicsDrawLine($backBuffer, $Width, $Height, $Width, $Height - $Lgth, $hPen1)
      _GDIPlus_GraphicsDrawLine($backBuffer, $Width, $Height, $Width - $Lgth, $Height, $hPen1) 
;Bottom Left 
      _GDIPlus_GraphicsDrawLine($backBuffer, 0, $Height, 0, $Height - $Lgth, $hPen1)
      _GDIPlus_GraphicsDrawLine($backBuffer, 0, $Height, $Lgth , $Height, $hPen1) 
_GDIPlus_PenDispose($hPen1) 
EndFunc
Func DrawDot() 
$dot_k -= 5
If $Dot_k <= -20 Then $dot_k = $Width
   _GDIPlus_GraphicsFillEllipse($backBuffer, $Dot_k, $Height/2 -20 ,40, 40)   ; Draw a Dot and move it
EndFunc  
; ============= Handle the WM_NCHITTEST message so our window can be dragged ===============
Func WM_NCHITTEST($hWnd, $iMsg, $iwParam, $ilParam)
Local $hMenu, $Win, $WinX, $WinY, $mX, $mY
if $hWnD = $GUI and _IsPressed (01) then Return $HTCAPTION 
EndFunc
#;======================================================================

; MouseWheel for Win Trans
Func WM_MOUSEWHEEL($hWnd, $iMsg, $wParam, $lParam)
  Local $mouseData, $n1
      $mouseData = _WinAPI_HiWord($wParam)
  
Select
;Case $wParam = $WM_MOUSEWHEEL And WinActive($GUI)
;WM_MOUSEWHEEL = 0x020A
Case WinActive($GUI)
   If $mouseData > 0 Then ;wheel up
    If $alpha + $alpha_steps <= 512 Then $alpha += $alpha_steps
    Switch $alpha
     Case 0 To 255
      DllStructSetData($tBlend, "Alpha", $alpha)          ; Set Alpha (Transparency) Level
      DllStructSetData($tBlend, "Format", 1)
     Case 256 To 512
      DllStructSetData($tBlend, "Alpha", $alpha - 256)
      DllStructSetData($tBlend, "Format", 0)
    EndSwitch
   Else ;wheel down
    If $alpha - $alpha_steps > 0 Then $alpha -= $alpha_steps
    Switch $alpha
     Case 0 To 255
      DllStructSetData($tBlend, "Alpha", $alpha) ;wheel up
      DllStructSetData($tBlend, "Format", 1)
     Case 256 To 512
      DllStructSetData($tBlend, "Alpha", $alpha - 256) ;wheel up
      DllStructSetData($tBlend, "Format", 0)
    EndSwitch
   EndIf
   ConsoleWrite($alpha & @CRLF)
EndSelect
EndFunc ;==>WM_MOUSEWHEEL
Func Close()
_WinAPI_DeleteDC($dc)
_WinAPI_ReleaseDC($GUI, $ScreenDc)
_GDIPlus_FontDispose($SC_hFont)
_GDIPlus_FontFamilyDispose($SC_hFamily)
_GDIPlus_StringFormatDispose($SC_hFormat)
_GDIPlus_GraphicsDispose($backbuffer)
_GDIPlus_BitmapDispose($bitmap)
_GDIPlus_GraphicsDispose($graphics)

  _GDIPlus_FontDispose    ($Time_hFont  )
  _GDIPlus_FontFamilyDispose  ($Time_hFamily)
  _GDIPlus_StringFormatDispose($Time_hFormat)
  _GDIPlus_BrushDispose    ($Time_hBrush)
_GDIPlus_Shutdown()
WinClose($GUI)
Exit
EndFunc   ;==>Close

Share this post


Link to post
Share on other sites

Posted (edited)

And this, not my script this one, search the forum for transparent GUI.

#include <GuiConstants.au3>
#include <WindowsConstants.au3>
HotKeySet("{ESC}", "QuitApp")
$Main_Gui = GUICreate("", 400, 400, 20, 20, $WS_POPUP, $WS_EX_TOOLWINDOW + $WS_EX_TOPMOST)
$But1 = GUICtrlCreateButton(" Exit ", 100, 100, 80, 21)
$Info_Edit = GUICtrlCreateEdit("A few words to start off with", 80, 150, 300, 220)
GUISetControlsVisible($Main_Gui)
GUISetState()
While 1
    If GUIGetMsg() = $But1 Then Exit
WEnd
Func GUISetControlsVisible($hWnd)
    Local $aClassList, $aM_Mask, $aCtrlPos, $aMask
  
    $aClassList = StringSplit(_WinGetClassListEx($hWnd), @LF)
    $aM_Mask = DllCall("gdi32.dll", "long", "CreateRectRgn", "long", 0, "long", 0, "long", 0, "long", 0)
  
    For $i = 1 To UBound($aClassList) - 1
        $aCtrlPos = ControlGetPos($hWnd, '', $aClassList[$i])
        If Not IsArray($aCtrlPos) Then ContinueLoop
      
        $aMask = DllCall("gdi32.dll", "long", "CreateRectRgn", _
            "long", $aCtrlPos[0], _
            "long", $aCtrlPos[1], _
            "long", $aCtrlPos[0] + $aCtrlPos[2], _
            "long", $aCtrlPos[1] + $aCtrlPos[3])
        DllCall("gdi32.dll", "long", "CombineRgn", "long", $aM_Mask[0], "long", $aMask[0], "long", $aM_Mask[0], "int", 2)
    Next
    DllCall("user32.dll", "long", "SetWindowRgn", "hwnd", $hWnd, "long", $aM_Mask[0], "int", 1)
EndFunc
Func _WinGetClassListEx($sTitle)
    Local $sClassList = WinGetClassList($sTitle)
    Local $aClassList = StringSplit($sClassList, @LF)
    Local $sRetClassList = "", $sHold_List = "|"
    Local $aiInHold, $iInHold
  
    For $i = 1 To UBound($aClassList) - 1
        If $aClassList[$i] = "" Then ContinueLoop
      
        If StringRegExp($sHold_List, "|" & $aClassList[$i] & "~(d+)|") Then
            $aiInHold = StringRegExp($sHold_List, ".*|" & $aClassList[$i] & "~(d+)|.*", 1)
            $iInHold = Number($aiInHold[UBound($aiInHold)-1])
          
            If $iInHold = 0 Then $iInHold += 1
          
            $aClassList[$i] &= "~" & $iInHold + 1
            $sHold_List &= $aClassList[$i] & "|"
          
            $sRetClassList &= $aClassList[$i] & @LF
        Else
            $aClassList[$i] &= "~1"
            $sHold_List &= $aClassList[$i] & "|"
            $sRetClassList &= $aClassList[$i] & @LF
        EndIf
    Next
  
    Return StringReplace(StringStripWS($sRetClassList, 3), "~", "")
EndFunc
Func QuitApp()
    Exit
EndFunc
Edited by Lakes

Share this post


Link to post
Share on other sites

Posted

guinness,

good work!

Is it possible to make the background transparent (control overlapping)?

Greets,

-supersonic.

Something like this here?

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


$w = 320
$h = 160
$y = $h + 1
$hGUI = GUICreate("Simple Scroller by UEZ 2011", $w, $h)
$idButton_Exit = GUICtrlCreateButton("Exit", 140, 60, 40, 40)
$idButton_Scroller = GUICtrlCreateButton("Scroller", 40, 60, 80, 40)
$hGUI_Child = GUICreate("", $w, $h, 0, 0, $WS_POPUP, $WS_EX_MDICHILD + $WS_EX_LAYERED, $hGUI)
GUISetBkColor(0xFEDCBA)
$idLabel_Scroller = GUICtrlCreateLabel(Scroller_Text(), 0, $y, $w, $h, $SS_CENTER)
GUICtrlSetBkColor(-1, -2)
GUICtrlSetColor(-1, 0x0000FF)
GUICtrlSetFont(-1, 16)
GUISetState(@SW_SHOW, $hGUI)
GUISetState(@SW_HIDE, $hGUI_Child)
_WinAPI_SetLayeredWindowAttributes($hGUI_Child, 0xFEDCBA)
$speed = 1



Do
    Switch GUIGetMsg()
        Case -3, $idButton_Exit
            ExitLoop
        Case $idButton_Scroller
            GUISetState(@SW_SHOW, $hGUI_Child)
            AdlibRegister("Scroll", 50)
    EndSwitch
Until False
GUIDelete()
Exit

Func Scroller_Text()
    Local $text =   "This is a simple scroller" & @LF & _
                            "made by " & @LF & _
                            "" & @LF & _
                            "UEZ 2011"
    Return $text
EndFunc

Func Scroll()
    ControlMove($hGUI_Child, "", $idLabel_Scroller, 0, $y)
    $y -= $speed
    If $y = -$h Then
        $y = $h + 1
        AdlibUnRegister("Scroll")
        GUISetState(@SW_HIDE, $hGUI_Child)
        ConsoleWrite("Scroller finished!" & @LF)
    EndIf
EndFunc

Br,

UEZ

Share this post


Link to post
Share on other sites

Posted (edited)

Thanks Lakes for your alternative. I was wondering if there was a workaround using only the HTML markup language but seems not.

Thanks as well UEZ for your alternative too.

Edited by guinness

Share this post


Link to post
Share on other sites

Posted

Another GDI+ alternative:

Br,

UEZ

Share this post


Link to post
Share on other sites

Posted (edited)

Greetings Guinness (yes I know the last post was in Dec. 2011).

I was perusing the examples in your signature and was checking this one out. I noticed when I run your example for some reason all of the 'N' and 'R' letters are being stripped from the displayed scrolling marquee. Anyone ideas why or anyone else experience this?

edit: only appears to affect lowercase 'n' and 'r' characters.

autoit ver 3.3.8.1

Edited by spudw2k

Share this post


Link to post
Share on other sites

Posted

Try again. The Forum was being difficult by removing the backslashes.

Share this post


Link to post
Share on other sites

Posted

Better now and I see what was going on. Thanks

Share this post


Link to post
Share on other sites

Posted

OK, so it was fixed?

Share this post


Link to post
Share on other sites

Posted

Yes sir. Thanks

Share this post


Link to post
Share on other sites

Posted

I wonder if a CSS3 & HTML5 equivalent can actually work in Shell.Explorer.2? Hmmm....

Share this post


Link to post
Share on other sites

Posted

This UDF is now deprecated.

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