Important alert: (current site time 7/16/2013 4:14:07 AM EDT)
 

VB icon

TextEffect

Email
Submitted on: 9/25/1998
By: Waty Thierry  
Level: Not Given
User Rating: By 1 Users
Compatibility: VB 4.0 (32-bit), VB 5.0, VB 6.0
Views: 38073
 
     The following code will add great text effect to your applications. It changes the spacing between the characters. By changing spaces, the characters move on the screen.
 

Windows API/Global Declarations:

Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
'**************************************
'Windows API/Global Declarations for :TextEffect
'**************************************
		
		' #VBIDEUtils#************************************************************
' * Programmer Name : Waty Thierry
' * Web Site : www.geocities.com/ResearchTriangle/6311/
' * E-Mail: waty.thierry@usa.net
' * Date : 24/09/98
' * Time : 15:38
' * Module Name : TextEffect_Module
' * Module Filename : TextEffect.bas
' **********************************************************************
' * Comments : Try this text effect, great effects
' *Ex :
' * TextEffect Picture1, "", 12, 12, , 128, 0, RGB(&H80, 0, 0)
' * TextEffect Me, "", 12, 12, , 128, 0, RGB(&H80, 0, 0)
' *
' *
' **********************************************************************
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
LeftAs Long
TopAs Long
Right As Long
Bottom As Long
End Type
Private Declare Function OffsetRect Lib "user32" (lpRect As RECT, ByVal x As Long, ByVal y As Long) As Long
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 TextOut Lib "GDI32" Alias "TextOutA" (ByVal hDC As Long, ByVal x As Long, ByVal y As Long, ByVal lpString As String, ByVal nCount As Long) As Long
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
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
'**************************************
' Name: TextEffect
' Description:The following code will add great text effect to your applications. It changes the spacing between the characters. By changing spaces, the characters move on the screen.
' By: Waty Thierry
'
' Inputs: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
'
' Assumes:Nothing.
Ex :
TextEffect Picture1, "", 12, 12, , 128, 0, RGB(&H80, 0, 0)
TextEffect Me, "", 12, 12, , 128, 0, RGB(&H80, 0, 0)
'
'This code is copyrighted and has' limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=1069&lngWId=1'for details.'**************************************

' #VBIDEUtils#************************************************************
' * Programmer Name : Waty Thierry
' * Web Site : www.geocities.com/ResearchTriangle/6311/
' * E-Mail: waty.thierry@usa.net
' * Date : 24/09/98
' * Time : 15:38
' * Module Name : TextEffect_Module
' * Module Filename : TextEffect.bas
' **********************************************************************
' * Comments : Try this text effect, great effects
' *Ex :
' * TextEffect Picture1, "", 12, 12, , 128, 0, RGB(&H80, 0, 0)
' * TextEffect Me, "", 12, 12, , 128, 0, RGB(&H80, 0, 0)
' *
' *
' **********************************************************************
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 OLE_COLOR = vbWindowText)
' #VBIDEUtils#************************************************************
' * Programmer Name : Waty Thierry
' * Web Site : www.geocities.com/ResearchTriangle/6311/
' * E-Mail: waty.thierry@usa.net
' * Date : 24/09/98
' * Time : 15:39
' * 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 iAs Long
Dim xAs Long
Dim lLen As Long
Dim hBrushAs Long
Static tRAs RECT
Dim iDir As Long
Dim bNotFirstTimeAs Boolean
Dim lTimeAs Long
Dim lIterAs Long
Dim bSlowDownAs Boolean
Dim lCOlorAs Long
Dim bDoItAs 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
 DoEvents
 If obj.Visible = False Then Exit Sub
 Loop While (timeGetTime - lTime) < 20
Loop
DeleteObject hBrush
End Sub


Other 2 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Not Given category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments
5/1/1999 3:47:00 AMccjx

send me a copy of that
(If this comment was disrespectful, please report it.)

 
6/20/1999 11:41:00 AMDan Sikorsky

OLE_COLOR is not defined as a user type. This needs to be done to pass the compliler.
(If this comment was disrespectful, please report it.)

 
7/19/1999 2:31:00 AMsaman

visual basic
(If this comment was disrespectful, please report it.)

 
8/28/1999 12:25:00 PMeisi

*PLEASE* copy all this source into
ONE File, so that you can download it easier.
thx, eisi
(If this comment was disrespectful, please report it.)

 
10/9/1999 10:17:00 PMhernán

this page is very good!!!!!.CONGRATULATIONS!!!!
Writeme please
(If this comment was disrespectful, please report it.)

 
10/27/1999 9:04:00 PMRenee

I can't get it to work, Please send me a zipped copy of the project
Thank you , Renee
(If this comment was disrespectful, please report it.)

 
12/22/1999 10:54:23 PMAlaeddin

Can you 'PLEASE' send me a working copy of this to my email.
I really appreciate this from you.
Thanks a lot man
(If this comment was disrespectful, please report it.)

 
2/24/2003 11:12:55 AMCy Toad

This dosen't appear to work on a text box or a label... Why would anyone want to change the text spacing in a Picture box, when you cant even put text in a picture box!!??
(If this comment was disrespectful, please report it.)

 
8/15/2003 8:53:02 AM

Can you 'PLEASE' send me a working copy
of this to my email.
I really
appreciate this from you.
Thanks a lot
man
(If this comment was disrespectful, please report it.)

 
4/27/2005 6:07:18 AM

can u help me with printing i am getting error 6 overflow
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.