[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Smooth Scrolling Text

Posted on 2004-11-04
12
Medium Priority
?
643 Views
Last Modified: 2012-06-27
I am trying to create a right-to-left text scroller similar to the news tickers found on TV channels like Sky News, etc.

The scrolling effect needs to be as smooth as possible (i.e. as close to broadcast quality as possible). It is feasable that a lot of CPU power can be used to process the scrolling if needbe.

I have investigated various examples using Hires (multimedia?) timers which seem to be the most sucessful, but the problem i have is that the text flickers and the scrolling is not smooth, especially ones which make use of moving labels.

Can somebody suggest some code which will render the scrolling effect with as little flicker as possible.

The text will be in Arial font, at least size 48
0
Comment
Question by:stuartlandreth
  • 7
  • 5
12 Comments
 

Author Comment

by:stuartlandreth
ID: 12494374
Supplemental to above, I already have code for a timer, which is firing (e.g.) every 20 milliseconds, so all I need is the text rendering code. Cheers.
0
 
LVL 9

Expert Comment

by:Shahid Thaika
ID: 12494496
Flickering may not neccessarily depend on the speed of the computer. It also depends on how you have written your code. You can have your text in a Label control with autosize property set to true and then can reduce the .Left property to simulate a text-scrolling. But if you do this, then you are sure to get flickering problems. Before I remember using the BitBlt API to draw many images on the form. I used to get lots of flickering problem. I solved this problem with using a time tested solution by using BitBlt on a buffer (Maybe a picturebox control). All the image copying and text coloring would be done to this buffer and the changes would not be seen due to it being invisible. Once the processing is over, I would simple copy the buffer to the form and voila, the flickering is gone. Maybe you could try this method.

Hope this answers your question :)
0
 

Author Comment

by:stuartlandreth
ID: 12494544
I managed to find this on an example

   Dim hRgn&
         
          '// print the text to the user control
          '// using paths
          With UserControl
            'open a path bracket
            BeginPath .hdc
            'draw the text
            TextOut .hdc, m_x&, 0, m_text$, Len(m_text$)
            'close the path bracket
            EndPath .hdc
            'convert the path to a region
            hRgn = PathToRegion(.hdc)
            'set the Window-region
            SetWindowRgn .hWnd, hRgn, True
            'destroy our region
            DeleteObject hRgn
         End With


which seems to use paths and regions, but still flickers a bit.

Can you give me an example of using BitBlt API as I am not not familiar with it. Thanks,.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 9

Expert Comment

by:Shahid Thaika
ID: 12494629
Please give me some time, I'll work on it.
0
 
LVL 9

Expert Comment

by:Shahid Thaika
ID: 12495103
Ok I got something that works without flickering, but may not be like the cool one's that you see on tv. One a new executable project, add a timer (Timer1) and a picture box control (Picture1). Then set the following properties.

Form (Form1):
ScaleMode: 3 - Pixel

Timer (Timer1):
Interval: 50

Picture control (Picture1):
ScaleMode: 3 - Pixel
Height: 30
AutoRedraw: True
Visible: False
Appearance: 0 - Flat
BorderStyle: 0 - None




Finally copy and paste the following code...
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long

Private Sub Form_Load()
'this sizes the picture box control according to our need
setPicSize "President George W. Bush has been re-elected in the USA elections"
End Sub

Private Sub setPicSize(strText As String)
'resize the control according to the size of the text
Picture1.Width = Picture1.TextWidth(strText) + 3
'set the starting point of the text to be printed
Picture1.CurrentX = 1
Picture1.CurrentY = (Picture1.Height - Picture1.TextHeight("*")) * 0.5
Picture1.Print strText
End Sub

Private Sub Timer1_Timer()
'variable to see how much from the left should we print
Static pX As Integer

'this copies the image from one place to another
Me.Cls
BitBlt Me.hDC, 0, Me.ScaleHeight - 30, Me.ScaleWidth, 30, Picture1.hDC, pX, 0, vbSrcCopy
pX = pX + 1
If pX > Picture1.Width Then pX = 10
End Sub
0
 
LVL 9

Expert Comment

by:Shahid Thaika
ID: 12495208
Oops, just found a mistake. In the second last line, the statement should be 'If pX > Picture1.Width Then pX = 0'

I would suggest you look up tutorials on BitBlt. There is a lot that you can do with it. :)
0
 

Author Comment

by:stuartlandreth
ID: 12495342
I appreciate the effort you have gone to with this code, but in-line with the size i need the scroller to be...

if you change the font in the picturebox to 48, perhaps white on black background and change

BitBlt Me.hDC, 0, Me.ScaleHeight - 30, Me.ScaleWidth, 30, Picture1.hDC, pX, 0, vbSrcCopy
to
BitBlt Me.hDC, 0, Me.ScaleHeight - 100, Me.ScaleWidth, 100,Picture1.hDC, pX, 0, vbSrcCopy

it flickers like mad!

any suggestions?
0
 

Author Comment

by:stuartlandreth
ID: 12495415
Aha - set the Form's Auto-Redraw to True and it seems to stop the flicker!!!
0
 
LVL 9

Expert Comment

by:Shahid Thaika
ID: 12495489
Firstly, in order to get white text on black background, just change the foreground property of the picture box to 'white' and 'backcolor' to 'black'

I changed the font property of the picture control to 'Arial (Bold), size 48'. I changed the height to 74

Finally, the flickering is not because of the BitBlt API. But maybe because of the Me.Cls statement. In order to correct this, I have removed the Me.Cls line and modified the line which resizes the picture control.


NEW CODE:




Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long

Private Sub Form_Load()
'this sizes the picture box control according to our need
setPicSize "President George W. Bush has been re-elected in the USA elections"
End Sub

Private Sub setPicSize(strText As String)
'resize the control according to the size of the text
Picture1.Width = Picture1.TextWidth(strText) + Me.ScaleWidth
'set the starting point of the text to be printed
Picture1.CurrentX = 1
Picture1.CurrentY = (Picture1.Height - Picture1.TextHeight("*")) * 0.5
Picture1.Print strText
End Sub

Private Sub Timer1_Timer()
'variable to see how much from the left should we print
Static pX As Integer

'this copies the image from one place to another
BitBlt Me.hDC, 0, Me.ScaleHeight - 74, Me.ScaleWidth, 74, Picture1.hDC, pX, 0, vbSrcCopy
pX = pX + 1
If pX > Picture1.Width Then pX = 0
End Sub



I am sure this will solve your problem :)
0
 
LVL 9

Accepted Solution

by:
Shahid Thaika earned 2000 total points
ID: 12495554
Setting the forms AutoRedraw property may have solved the problem. But depending on your software, it may not be desirable.
0
 

Author Comment

by:stuartlandreth
ID: 12495679
Thanks!!!!!

I have now sucesfully integrated this with the hi-res timer code and have a very nicely smooth scrolling text scroller!

0
 
LVL 9

Expert Comment

by:Shahid Thaika
ID: 12501881
Best of Luck for your project :)
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month19 days, 13 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question