Solved

How to prevent flickering of graphics

Posted on 2002-04-23
5
315 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Controlling which port to download from 4 71
Adding to a VBA? 6 61
VBA Shell can't Find Word document 11 76
How to hault or freeze parent form when a 2d form is open in vb6 3 35
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

912 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now