Solved

How to prevent flickering of graphics

Posted on 2002-04-23
5
319 Views
Last Modified: 2012-08-14
I'm writing a card game in VB 6.0 for fun, using cards.dll - the Microsoft card game DLL that games like Hearts and Solitaire use.

My forms use AutoDraw=False and ClipControls=False, and use the Form_Paint() method to update the screen when necessary via Refresh. The problem is that the screen flickers sometimes during the update. Otherwise, it works great. What's the problem?
0
Comment
Question by:dplambert
5 Comments
 
LVL 7

Expert Comment

by:Z_Beeblebrox
ID: 6962738
In general flickering is noticeable when you update something that you don't need to. Try just redrawing those things that have actually changed. Another tehnique is to hide everything on your form, make the changes, then show it again. From the users perspective, they don't see anything get hidden because you never release the processor to hide the stuff, so it just looks like everything changed at once.

Zaphod.
0
 
LVL 18

Accepted Solution

by:
mdougan earned 50 total points
ID: 6962808
AutoRedraw to True might help as well, because then VB updates the image buffer first, and then pages it into the form for a faster refresh.
0
 
LVL 3

Author Comment

by:dplambert
ID: 6962899
I changed ClipControls=True and it works great. No more flickering.
0
 
LVL 3

Expert Comment

by:n_narayanan
ID: 6963034
Often when updating a Treeview, ListView etc. a lot of flickering takes place. To prevent this create a class called Freeze and use it in your form like this: Dim Freeze as New Freeze Freeze.Form Me when the scope goes out range the class will destroy itself and everything will be back to normal.



'declare function to stop window flickering when loading / updating forms
Private Declare Function LockWindowUpdate Lib _
"USER32" (ByVal hwndLock As Long) As Long

Option Explicit

Public Sub Form(pForm As Form)
    LockWindowUpdate pForm.hWnd
End Sub

Private Sub Class_Initialize()
    'check who called the class
End Sub

Private Sub Class_Terminate()
    LockWindowUpdate False
End Sub

The above code is taken from

http://www.freevbcode.com/ShowCode.ASP?SearchString=flickering%20stop&ID=141

0
 
LVL 3

Author Comment

by:dplambert
ID: 6972650
Everyone had valid comments. I most likely will use the hide/show before releasing the processor like the first comment reads if it's still an issue...
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Windows 10 start screen issues 9 55
Computer crashes, following error message in event manager 5 202
using web browser with BING 40 122
Excel Automation VBA 19 74
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…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…

831 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