May 15, 1995
You can add visual appeal to your Visual Basic® applications by including a routine that automatically scrolls text vertically within a picture box. This article explains how you can add this functionality to your programs.
The Windows® application programming interface (API) BitBlt function can be used to copy a section of a Picture Box control to another section of that same control. You must remember to set the ScaleMode property of the Picture Box control to Pixel mode.
The example program below shows how to use the BitBlt function to print scrolling text on a Picture Box control. A Timer control is used to print a string of text on the Picture Box control at selected time intervals.
Const SRCCOPY = &HCC0020
Const ShowText$ = "This line of text scrolls vertically."
Private Declare Function BitBlt Lib "GDI" (ByVal hDestDC As Integer, ByVal X
As Integer, ByVal Y As Integer, ByVal nWidth As Integer, ByVal nHeight
As Integer, ByVal hSrcDC As Integer, ByVal XSrc As Integer, ByVal YSrc
As Integer, ByVal dwRop As Long) As Integer
Dim ShowIt%
Private Sub Timer1_Timer()
Dim Ret As Integer
If (ShowIt% = 30) Then
Picture1.CurrentX = 0
Picture1.CurrentY = Picture1.ScaleHeight - 30
Picture1.Print ShowText$
ShowIt% = 0
Else
Ret = BitBlt(Picture1.hDC, 0, 0, Picture1.ScaleWidth,
Picture1.ScaleHeight - 1, Picture1.hDC, 0, 1, SRCCOPY)
ShowIt% = ShowIt% + 1
End If
End Sub
Run the program by pressing the F5 function key. After a short time, the text "This line of text scrolls vertically." will be displayed in the Picture Box control. Each time the Timer control reaches 25, the line of text will be scrolled upward in the Picture Box control.
"Tip 45: Using BitBlt to Display Bitmaps."
"BITBLT: Tests the BitBlt Function." (MSDN Library Archive, Sample Code, Sample City, Visual Basic Samples)
Knowledge Base Q71104. "How to Use Windows BitBlt Function in Visual Basic Application."