Quantcast
Channel: VBForums - CodeBank - Visual Basic 6 and earlier
Viewing all articles
Browse latest Browse all 1461

Funny Text Effect (for spalsh screen for instance)

$
0
0
This code is a very very old code (more than 20 years) I used in my apps to add some annimation during loading, on the splash screen

Justs call (adapting the parameters of course)
TextEffect Me, "This is a funny and easy Text effect", 120, 50, False, 50, 0, vbRed

Code:

' #VBIDEUtils#************************************************************
' * Programmer Name  :
' * Web Site        :
' * E-Mail          :
' * Date            : 08/11/1999
' * Time            : 10:56
' * Module Name      : TextEffect_Module
' * Module Filename  : TextEffect.bas
' **********************************************************************
' * Comments        :
' *
' *
' **********************************************************************

Option Explicit

Private Declare Function timeGetTime Lib "winmm.dll" () As Long
Private Declare Function SetTextCharacterExtra Lib "gdi32" (ByVal hdc As Long, ByVal nCharExtra As Long) As Long

Private Type RECT
  Left                As Long
  Top                  As Long
  Right                As Long
  Bottom              As Long
End Type

Private Declare Function SetTextColor Lib "gdi32" (ByVal hdc As Long, ByVal crColor As Long) As Long
Private Declare Function FillRect Lib "user32" (ByVal hdc As Long, lpRect As RECT, ByVal hbrush As Long) As Long
Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function GetSysColor Lib "user32" (ByVal nIndex As Long) As Long

Private Const COLOR_BTNFACE = 15

Private Declare Function DrawText Lib "user32" Alias "DrawTextA" (ByVal hdc As Long, ByVal lpStr As String, ByVal nCount As Long, lpRect As RECT, ByVal wFormat As Long) As Long

Private Const DT_BOTTOM = &H8
Private Const DT_CALCRECT = &H400
Private Const DT_CENTER = &H1
Private Const DT_CHARSTREAM = 4          '  Character-stream, PLP
Private Const DT_DISPFILE = 6            '  Display-file
Private Const DT_EXPANDTABS = &H40
Private Const DT_EXTERNALLEADING = &H200
Private Const DT_INTERNAL = &H1000
Private Const DT_LEFT = &H0
Private Const DT_METAFILE = 5            '  Metafile, VDM
Private Const DT_NOCLIP = &H100
Private Const DT_NOPREFIX = &H800
Private Const DT_PLOTTER = 0            '  Vector plotter
Private Const DT_RASCAMERA = 3          '  Raster camera
Private Const DT_RASDISPLAY = 1          '  Raster display
Private Const DT_RASPRINTER = 2          '  Raster printer
Private Const DT_RIGHT = &H2
Private Const DT_SINGLELINE = &H20
Private Const DT_TABSTOP = &H80
Private Const DT_TOP = &H0
Private Const DT_VCENTER = &H4
Private Const DT_WORDBREAK = &H10

Private Declare Function OleTranslateColor Lib "OLEPRO32.DLL" (ByVal OLE_COLOR As Long, ByVal HPALETTE As Long, pccolorref As Long) As Long
Private Const CLR_INVALID = -1

Public Sub TextEffect(Obj As Object, ByVal sText As String, ByVal lX As Long, ByVal lY As Long, Optional ByVal bLoop As Boolean = False, Optional ByVal lStartSpacing As Long = 128, Optional ByVal lEndSpacing As Long = -1, Optional ByVal oColor As Long = vbWindowText)
  ' #VBIDEUtils#************************************************************
  ' * Programmer Name  :
  ' * Web Site        :
  ' * E-Mail          :
  ' * Date            : 08/11/1999
  ' * Time            : 10:56
  ' * Module Name      : TextEffect_Module
  ' * Module Filename  : TextEffect.bas
  ' * Procedure Name  : TextEffect
  ' * Parameters      :
  ' *                    obj As Object
  ' *                    ByVal sText As String
  ' *                    ByVal lX As Long
  ' *                    ByVal lY As Long
  ' *                    Optional ByVal bLoop As Boolean = False
  ' *                    Optional ByVal lStartSpacing As Long = 128
  ' *                    Optional ByVal lEndSpacing As Long = -1
  ' *                    Optional ByVal oColor As OLE_COLOR = vbWindowText
  ' **********************************************************************
  ' * Comments        :
  ' *
  ' *
  ' **********************************************************************

  ' *** Kerning describes the spacing between characters when a font is written out.
  ' *** By default, fonts have a preset default kerning, but this very easy to modify
  ' *** under the Win32 API.

  ' *** The following (rather unusally named?) API function is all you need:
  ' *** Private Declare Function SetTextCharacterExtra Lib "gdi32" () (ByVal hdc As Long, ByVal nCharExtra As Long) As Long
  ' *** By setting nCharExtra to a negative value, you bring the characters closer together,
  ' *** and by setting to a positive values the characters space out.
  ' *** It works with VB's print methods too.

  Dim lHDC            As Long
  Dim i                As Long
  Dim x                As Long
  Dim lLen            As Long
  Dim hbrush          As Long
  Static tR            As RECT
  Dim iDir            As Long
  Dim lTime            As Long
  Dim lIter            As Long
  Dim bSlowDown        As Boolean
  Dim lColor          As Long
  Dim bDoIt            As Boolean

  lHDC = Obj.hdc
  iDir = -1
  i = lStartSpacing
  tR.Left = lX
  tR.Top = lY
  tR.Right = lX
  tR.Bottom = lY

  OleTranslateColor oColor, 0, lColor

  hbrush = CreateSolidBrush(GetSysColor(COLOR_BTNFACE))
  lLen = Len(sText)

  SetTextColor lHDC, lColor
  bDoIt = True

  Do While bDoIt
      lTime = timeGetTime
      If (i < -3) And Not (bLoop) And Not (bSlowDown) Then
        bSlowDown = True
        iDir = 1
        lIter = (i + 4)
      End If
      If (i > 128) Then iDir = -1
      If Not (bLoop) And iDir = 1 Then
        If (i = lEndSpacing) Then
            ' Stop
            bDoIt = False
        Else
            lIter = lIter - 1
            If (lIter <= 0) Then
              i = i + iDir
              lIter = (i + 4)
            End If
        End If
      Else
        i = i + iDir
      End If

      FillRect lHDC, tR, hbrush
      x = 32 - (i * lLen)
      SetTextCharacterExtra lHDC, i
      DrawText lHDC, sText, lLen, tR, DT_CALCRECT
      tR.Right = tR.Right + 4
      If (tR.Right > Obj.ScaleWidth \ Screen.TwipsPerPixelX) Then tR.Right = Obj.ScaleWidth \ Screen.TwipsPerPixelX
      DrawText lHDC, sText, lLen, tR, DT_LEFT
      Obj.Refresh

      Do
        If Obj.Visible = False Then Exit Sub
      Loop While (timeGetTime - lTime) < 20
  Loop
  DeleteObject hbrush

End Sub

Sample app TextEffect.zip
Attached Files

Viewing all articles
Browse latest Browse all 1461

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>