Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Donate Today!

Do you enjoy these
technical forums?
Donate Today! Click Here

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

RMS001 (Programmer) (OP)
25 Feb 05 3:34
I would like to be able to do a refresh on a form without redrawing the entire form area. The reason is to be able to move an object within a picture box and not have so much flashing. (Refreshing just the picture box does not work. The whole form must be refreshed or the object leaves trails.)

I've tried to use examples from allapi but nothing pertains to this particular situation:

Get old clipping device context

Save old values

Set new clipping region (smaller)

Move object (a visual basic shape)

Reset old clipping region

Any help would be welcome - Thanx
comaboy (Programmer)
16 Mar 05 7:00
RMS,

I may be barking up the wrong tree but, try this:
Blank form.
Add two Pictureboxes.
Set Picture1's Picture property to to an icon, whatever
Leave Picture2 blank.
Slap the following code into the form:

CODE

Option Explicit

'There are two Pictureboxes on the form.
'Picture1 has an icon in it.
'Picture2 is blank ,ie, Picture:(None)

Private Sub Form_Load()
    Show 'the form
    Dim x As Long
    Dim y As Long
    Form1.ScaleMode = vbPixels
    Picture1.ScaleMode = vbPixels
    For y = 1 To 1000 Step 1
        For x = 1 To 1000 Step 1
            Picture2.Cls
            Picture2.PaintPicture Picture1.Picture, x, y
        Next
        y = y + 1
        For x = 1000 To 1 Step -1
            Picture2.Cls
            Picture2.PaintPicture Picture1.Picture, x, y
        Next
    Next
End Sub

What I end up with is blur as the icon "pingpongs" down Picture2. Now I presume you're animating on some sort of Timer basis (haven't the time to knock up a proper animation routine). In this case the Form_Load eats CPU cycles, but the form remains steady. Does this help? Certainly simpler than delving into the API...

...API experts begin your flames now... ;)
strongm (MIS)
16 Mar 05 10:37
>What I end up with is blur

That isn't a blur, that is exactly the flicker that the OP is asking how to avoid
strongm (MIS)
16 Mar 05 15:25
>Refreshing just the picture box does not work. The whole form must be refreshed or the object leaves trails

Not entirely true. The following simple example (which includes 1 API call simply to slow everything down so we can see it) shows animation in a picture box using refresh with no trails and only a small amount flicker.

You'll need a picturebox (fill it with a nice image if you like to show that we can render on top without disturbing it) and two command buttons:

CODE

Option Explicit
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Const MaxScale = 500
Private UserStop As Boolean

Private Sub Command1_Click()
    Dim lp As Long
    Dim IL As Object
    Dim IconPicture As StdPicture
    
    Set IL = CreateObject("MSComCtlLib.imagelistctrl")
    SetUpMasterPicture
    
    IL.MaskColor = RGB(255, 255, 255)
    IL.ListImages.Add , , LoadPicture("c:\program files\microsoft visual studio\common\graphics\bitmaps\assorted\smokes.bmp") 'icons\misc\Face02.ico")
    Set IconPicture = IL.ListImages(1).ExtractIcon
    
    Do
        For lp = 0 To MaxScale
            Picture1.PaintPicture IconPicture, lp, MaxScale / 2 - IconPicture.Height / (2 * Screen.TwipsPerPixelY)
            Sleep 5 ' Just put in a delay so we can see the animation...
            Picture1.Refresh
            DoEvents
        Next
    Loop Until UserStop
End Sub

Private Sub Command2_Click()
    UserStop = True
End Sub


Private Sub SetUpMasterPicture()
    Picture1.ScaleWidth = MaxScale
    Picture1.ScaleHeight = MaxScale
    Picture1.AutoRedraw = False
End Sub
RMS001 (Programmer) (OP)
16 Mar 05 17:54
Hi strongm

As usual, with every piece of code you write and post I learn something new and useful!
I wish I could join you on a pub outing and sit for an evening and chat. (Continents away.)

When I used to write code for the Commodore 64, it was possible to interrupt the raster scan and move the sprites while the screen was in blanking mode. I guess I will have to migrate to VC++ to really get control of the graphics. It's just that almost every aspect of "6" is solvable with some help and experimentation.

I guess if it was possible to wait for the runtime to be ready to do a screen update, it would smooth things out. In the case I'm dealing with timing is not important.(The flashing is random - most times it does not occur). I am dragging a label and shape to a new location and adding text to the label from a separate (non-moving) textbox. Because I am using fancy fonts, the backspace leaves artifacts which have to be cleaned up with a Refresh. This also randomly causes flicker.

THANX! again as always...

-Ron
comaboy (Programmer)
17 Mar 05 4:25
OK,

So I was barking up the wrong tree!

Strongm, nice code, though. Very clever. However, as I pointed out, I'd use a timed sub to move the picture every x millisecs - which would smooth things out no end. Mind you, since I misunderstood the problem, the code is useless anyway! (Other than to play with a bit of animation)

All the best!
RMS001 (Programmer) (OP)
17 Mar 05 13:01
Thanks comaboy
The more code we see, the more ideas we can ingest.
- Ron
comaboy (Programmer)
18 Mar 05 3:19

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close