473,846 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Scrolling text that doesn't flicker

Hi,
I have seen loads of different ways to do this, but the all seem to
yield the same result - text that doesn't flicker when it's moving too
slowly!
Does anyone know 'the best way' to make text scroll...

eg
Override OnPain and OnPaintBackgrou nd

Override WndProc

Use GDI

Use API

Or do i need to create some weird control in c++?!

Thanks in advance,
James

Nov 12 '06 #1
17 4768
"pigeonrand le" <pi**********@h otmail.comwrote in message
news:11******** *************@i 42g2000cwa.goog legroups.com...
Hi,
I have seen loads of different ways to do this, but the all seem to
yield the same result - text that doesn't flicker when it's moving too
slowly!
"Flicker" is generally caused by a single problem, regardless of what you're
drawing: erasing the previous image on-screen before drawing the new image.

Typically, this is addressed using an off-screen buffer to actually draw the
image, which is then copied directly to the screen without erasing whatever
was there previously. The reason you need to erase in the first place is to
get rid of whatever was there previously, but if you are always copying a
whole new bitmap (or portion of a bitmap) on top of every part of the
display that needs changing, then no erasing is necessary, and no flicker
occurs.

In .NET, I've been told one can enable "double-buffering" to address this.
The term "double-buffering" isn't correct, IMHO (it more correctly refers to
a related but different idea in which the entire screen buffer is switched
back and forth), but knowing that that's the phrase some .NET people use may
help you find the technique in the .NET documentation. I haven't used it
myself, so I can't tell you the specifics.

Pete
Nov 12 '06 #2
Hi James,

As Peter suggested, double buffering is an option to reduce flickering (the
only one I'm aware of as well). In the constructor of a class that derives
from Control (including the Form class) you can use the following code to
enable double buffering for that control (1.* applications):

this.SetStyle(C ontrolStyles.Do ubleBuffer
| ControlStyles.A llPaintingInWmP aint
| ControlStyles.U serPaint, true);

In 2.0 apps, just set the Control.DoubleB uffered property to true (it uses the
new ControlStyles.O ptimizedDoubleB uffer flag internally).

--
Dave Sexton

"pigeonrand le" <pi**********@h otmail.comwrote in message
news:11******** *************@i 42g2000cwa.goog legroups.com...
Hi,
I have seen loads of different ways to do this, but the all seem to
yield the same result - text that doesn't flicker when it's moving too
slowly!
Does anyone know 'the best way' to make text scroll...

eg
Override OnPain and OnPaintBackgrou nd

Override WndProc

Use GDI

Use API

Or do i need to create some weird control in c++?!

Thanks in advance,
James

Nov 13 '06 #3
"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
news:up******** ******@TK2MSFTN GP03.phx.gbl...
Hi James,

As Peter suggested, double buffering is an option to reduce flickering
(the only one I'm aware of as well).
The other option is to just draw everything once. If you are doing something
like a chessboard this is easy, just draw each square onto the screen. If
the chessboard has pieces you could use regions to draw the pieces and then
draw the square around them. Unfortunately for text I don't think this is
possible. You have to use double buffering because it's not possible to draw
text with a background and it is not possible to find the region surrounding
this text. This also applies to many of the features of GDI+ such as
anti-aliasing and transparencies, it's no longer possible to draw in one go
so double buffering is almost mandatory these days.

Michael
Nov 13 '06 #4
Hi Michael,

But for scrolling text you can't draw everything only once. It's scrolling!

BTW, you can draw text with a background color in the 2.0 framework using the
TextRenderer class, which I believe uses GDI, not GDI+.

--
Dave Sexton

"Michael C" <no****@nospam. comwrote in message
news:u2******** ******@TK2MSFTN GP03.phx.gbl...
"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
news:up******** ******@TK2MSFTN GP03.phx.gbl...
>Hi James,

As Peter suggested, double buffering is an option to reduce flickering (the
only one I'm aware of as well).

The other option is to just draw everything once. If you are doing something
like a chessboard this is easy, just draw each square onto the screen. If
the chessboard has pieces you could use regions to draw the pieces and then
draw the square around them. Unfortunately for text I don't think this is
possible. You have to use double buffering because it's not possible to draw
text with a background and it is not possible to find the region surrounding
this text. This also applies to many of the features of GDI+ such as
anti-aliasing and transparencies, it's no longer possible to draw in one go
so double buffering is almost mandatory these days.

Michael

Nov 13 '06 #5
"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
news:O9******** ******@TK2MSFTN GP04.phx.gbl...
Hi Michael,

But for scrolling text you can't draw everything only once. It's
scrolling!
Yes, you can (assuming you can draw the background with the text as you
described). There will be x frames per second, for each frame if you draw
each pixel on the surface only once then you don't need double buffering.
BTW, you can draw text with a background color in the 2.0 framework using
the TextRenderer class, which I believe uses GDI, not GDI+.
If that's the case then it would be possible to use the API directly in 1.1,
although I don't recall there being an API that would let you draw text with
a background.

Michael
Nov 13 '06 #6
"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
news:O9******** ******@TK2MSFTN GP04.phx.gbl...
But for scrolling text you can't draw everything only once. It's
scrolling!
The other thing you can do with scrolling text is use the ScrollWindow API
to move the contents of the window towards the left and then fill in the
invalid areas.

Michael
Nov 13 '06 #7
Hi Michael,
>But for scrolling text you can't draw everything only once. It's
scrolling!

Yes, you can (assuming you can draw the background with the text as you
described). There will be x frames per second, for each frame if you draw
each pixel on the surface only once then you don't need double buffering.
I really don't understand what you mean. How would that prevent Windows from
clearing the render target before the next operation?

I always thought double-buffering worked like the swap chain in DirectX, where
the back buffer is simply presented instead of the target being cleared.
Without the buffer, I assumed Windows will clear the target automatically for
each WM_PAINT message, causing a flicker.

Care to explain in more detail?
>BTW, you can draw text with a background color in the 2.0 framework using
the TextRenderer class, which I believe uses GDI, not GDI+.

If that's the case then it would be possible to use the API directly in 1.1,
although I don't recall there being an API that would let you draw text with
a background.
Yea, I'm not sure how they do it but it's there and it works (and it's GDI
according to the MSDN docs :)

--
Dave Sexton
Nov 13 '06 #8
"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
news:O9******** ******@TK2MSFTN GP04.phx.gbl...
Hi Michael,

But for scrolling text you can't draw everything only once. It's
scrolling!
As Michael notes, in theory as long as you ensure that every pixel that
needs to change is drawn, you can avoid the flickering.

However...it's MUCH harder to accomplish this, and in some cases may be
impossible of course. Even with the original GDI, while it might have been
theoretically possible to draw the text, and fill the region outside the
text with the background color, that would have been such an expensive
drawing operation, no one sensible person would have done it that way.

The most common solution would have been to simply maintain a bitmap the
same size as the on-screen window, drawing into that and then blting the
results to the screen. Another solution would be to use smaller bitmaps,
the size of whatever it is you want to draw, blt those as they are drawn to
the appropriate spot on the screen. Of course, as was noted in Michael's
earlier post, if the kinds of things that are being drawn lend themselves to
simply copy an entire image to fill a specific area on the screen, then that
works too.

The key in all solutions is to avoid first clearing an area on the screen
and then drawing something else on top of that.
BTW, you can draw text with a background color in the 2.0 framework using
the TextRenderer class, which I believe uses GDI, not GDI+.
It's been awhile, but my recollection is that this doesn't make a
difference. That is, when drawing text with a background color (using the
opaque style), GDI would first fill in the background and then draw the
text, all directly to the destination DC. It didn't avoid flickering...it
just was more convenient than calling FillRect directly yourself (and also
had the advantage that you didn't have to measure the text first, since the
TextOut function handled the whole thing for you).

Even if using "double buffering" (sorry, I still hate that term as applied
here) could be avoided and dealing with updating screen graphics could be
solved some other way, IMHO there's not really any great reason to do so.
Using an off-screen bitmap, as in "double buffering", is a reasonably
elegant way to address a variety of complications that come up with any sort
of animated or changing display, and with the amount of RAM available on
most systems these days, doesn't incur much of a penalty.

Pete
Nov 13 '06 #9
"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
news:%2******** ********@TK2MSF TNGP04.phx.gbl. ..
>>But for scrolling text you can't draw everything only once. It's
scrolling!

Yes, you can (assuming you can draw the background with the text as you
described). There will be x frames per second, for each frame if you draw
each pixel on the surface only once then you don't need double buffering.

I really don't understand what you mean. How would that prevent Windows
from clearing the render target before the next operation?
He's saying that, if you had a way to ensure that each pixel on the screen
that has changed is drawn only once, setting it to the exact desired new
value, you can, once per frame, draw everything only once.

Obviously something animated has to be drawn multiple times. But the
flicker doesn't result from that. It results from drawing things multiple
times *per frame*. That's what he means to avoid.

In theory, it's even possible to do so (see my other post, about using
regions to mask the text area while filling the remaining background). In
reality, that's a) a much more complicated solution than using an off-screen
buffer, and b) may not even perform as well (since it would rely on using
regions to mask the text area while the background is being drawn).
I always thought double-buffering worked like the swap chain in DirectX,
where the back buffer is simply presented instead of the target being
cleared. Without the buffer, I assumed Windows will clear the target
automatically for each WM_PAINT message, causing a flicker.

Care to explain in more detail?
This is why I dislike the use of the term "double buffering" to describe
this. It's similar to, but not exactly the same as, the existing
double-buffering (or even triple-buffering, as is sometimes the case) used
in DirectDraw. In DirectDraw, double-buffering means there are two entire
frame buffers. One is always being used by the video card's RAMDAC to
display an image on the monitor, and the other is the one being drawn to at
that given moment. Once drawing has been completed, the entire active frame
buffer is switched (flipped), and the process starts anew.

This is kind of what the .NET "double buffering" is doing, except that it's
not a low-level hardware thing. There's an alternate, off-screen buffer and
rather than flipping the actively displayed buffer, the off-screen buffer is
simply copied to the active on-screen buffer. I don't like using the same
term for both, because it confuses the issue.

By doing this, any pixel that changes on the screen is drawn exactly once
for a given change (frame). Which is what needs to happen to avoid flicker.
And it certainly can happen that way, even as the text is scrolling. The
requirement is that the drawing happens once for each change, not that it
only happen once period.

Pete
Nov 13 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
3872
by: Marek Mänd | last post by:
This seems an IE issue only: 4253 bytes testcase: http://www.hot.ee/idaliiga/testcases/ieselect/bnlinkingselectinmsie.htm Can one have 1) a mouseover/mouseout element on TBODY 2) change in thoise event handler background colors 3) have a specified heighted SELECT element, that doesnt flicker when the event handlers are get called.
0
1910
by: mp3boss | last post by:
I am updating a string in the format MM:SS every second using the On_Timer event in Access97 by changing the caption of a label. Even though I'm using 8point text, the box sometimes flickers (transparent background changes to light-gray before reverting back to transparent). The text is drawn on top of a rectangle that is on top of a form that may have an embedded picture. If I create a very-simple form without all of these elements, I...
0
1275
by: Aku | last post by:
Hello, I have a RichTextBox located in a TabPage area; when I enter the RTBox space I displayed a certain text on it (using MouseEnter event). When I leave the RTBox space I displayed another (default-) text (using MouseLeave event). The problem: when entering the space, the text length is of such length that a VerticalScroll bar pops up. When I tried to scroll down by clicking on the bar or just touch the scroll bar, the displayed text...
0
1302
by: alex sparsky | last post by:
I've written a small control that doesn't do much other than draw some things on the screen with the drawing classes. I am using double buffer as well as doing an internal drawing to buffer on a GDI bitmap. For some reason on some machines, this causes the desktop to flicker like mad. On other machines I see no flicker at all. The actual app doesn't flicker, but the desktop does! Anyone have any ideas what I might be doing that would...
3
5682
by: seamlyne | last post by:
The first method I ever used for multiple state buttons was to create a graphic for each button for each state: AboutUs_on, AbooutUs_over, AboutUs_out, etc. That works great when there are just a few buttons. I'm creating interfaces now with many more buttons than "just a few". I solved the maintenance problem by having generic button images, one for each state, and having them be background images for text containers, DIVs in this...
13
3390
by: WALDO | last post by:
I have a .Net TextBox (TextBoxBase, really) in which I am appending about 20 lines of text per second. I use the AppendText() method to accomplish this. This is a great substitute for taking the Text property and concatenating it... Me.tb.Text &= newText ' Instead use Me.tb.AppendText(newText) ....ultimately setting the SelectionStart to the end of TextBox, the
4
9628
by: huntingseasonson | last post by:
Hi, I have set up the following page http://gertrudischale.com/cgi/ viewart.pl?lang=en&i=22 to scroll in the same direction one moves the mouse. This works fine -except in IE- where the image tends to flicker when the scrolling takes place. Is there an alternative way to achieve the scrolling with out the causing the flicker? The code is as follows:
11
7659
by: =?Utf-8?B?UmF5IE1pdGNoZWxs?= | last post by:
Hello, I know I sound like a one-note Johnny on this but I'm still looking for a solution. I need to display characters coming in from a serial port or a socket. I also need to be able to type characters into the display myself - but that's not the main issue at this time. I've tried a scrolling multiline text box but once the original viewable area fills up and it starts scrolling the flashing of the entire area drives me nuts. The...
0
9725
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10976
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10640
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10330
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7877
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7050
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4521
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4111
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3157
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.