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

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 346
  • Last Modified:

How to prevent flickering of graphics

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
dplambert
Asked:
dplambert
1 Solution
 
Z_BeeblebroxCommented:
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
 
mdouganCommented:
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
 
dplambertAuthor Commented:
I changed ClipControls=True and it works great. No more flickering.
0
 
n_narayananCommented:
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
 
dplambertAuthor Commented:
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

Independent Software Vendors: 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!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now