Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Screen Flickering

Status
Not open for further replies.

bjd4jc

Programmer
Nov 8, 2001
1,627
US
I am creating a type of screen saver that is built into my application (the windows one is disabled). I am trying to reduce if not eliminate the flickering of it. It is a form and a label that "bounces" off the forms edges. Below is the code that I am using. I have read several posts on here about different techniques and haven't had much luck. I thought that someone here could look at my code and give me an idea of where I could head next. The form is in the 0,0 position of the screen and fills the height and width of the screen. The timer interval is set to 500. The LeftIncr value is 125 and the TopIncr value is 75

Code:
Private Sub tmrMove_Timer()
    Static MovingLeft As Boolean
    Static MovingUp As Boolean
    Dim NewLeft As Single
    Dim NewTop As Single
    
    tmrQuit.Enabled = False
    tmrMove.Enabled = False
    tmrTime.Enabled = False
    
    LockWindowUpdate Me.hwnd
    
    If MovingLeft Then
        If (lblMessage.Left - LeftIncr) < 0 Then
            NewLeft = 0
            lblMessage.Move 0
            MovingLeft = Not MovingLeft
        Else
            NewLeft = lblMessage.Left - LeftIncr
        End If
    Else
        If (lblMessage.Left + lblMessage.Width + LeftIncr) > Me.Width Then
            NewLeft = Me.Width - lblMessage.Width
            MovingLeft = Not MovingLeft
        Else
            NewLeft = lblMessage.Left + LeftIncr
        End If
    End If
    
    If MovingUp Then
        If (lblMessage.Top - TopIncr) < 0 Then
            NewTop = 0
            MovingUp = Not MovingUp
        Else
            NewTop = lblMessage.Top - TopIncr
        End If
    Else
        If (lblMessage.Top + lblMessage.Height + TopIncr) > Me.Height Then
            NewTop = Me.Height - lblMessage.Height
            MovingUp = Not MovingUp
        Else
            NewTop = lblMessage.Top + TopIncr
            lblMessage.Top = lblMessage.Top + TopIncr
        End If
    End If
    
    lblMessage.Move NewLeft, NewTop
    
    LockWindowUpdate 0&
    tmrQuit.Enabled = True
    tmrMove.Enabled = True
    tmrTime.Enabled = True
End Sub
 
I had it set to false. Changed it to true and it is still flickering.
 

Ok with it set to false and the use of lockwindowupdate is probably the problem. Search the web for double buffer for example on how to use this method with vb and its pros and cons.

Good Luck

 
OK.

This may see a bit tough but the only way to avoid flickering is to use API. I have done a lot such work, but more than year ago - not sure if I remember everything.

1. You need to get your graphic into memory. You should use true memory hDCs for serious work, but invisible pictures will do there. So just load you graphic (the bouncing picture) into a picturebox and make the picture invisible. this is hDC1.
2. Similarly create another picturebox hDC hdc2 with no graphic so far.
3. Blit by BitBlt API e.g. from left corner of the form to hDc2. It means BitBlt Form1.hdc -> Picture2.hDc
4. Blit from hDC1 to the left corner of the form to create the picture. It means BitBlt Picture1.hdc -> Form1.hDc
5. After a while, blit back from hDc2 to left corner of the form to erase the picture.
6. Blit form the center of the form to hdc2.
7. Blit from hdc1 to the center of the form to create the picture .....

Got it? Autoredraw =false! No moreflickering.


If you need to change the text just use the DrawText or TextOut Api after bliting from hDC1.



<a href='
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top