Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • 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!
  • Students Click Here

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

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


Clipping Area of a Window

Clipping Area of a Window

Clipping Area of a Window

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

RE: Clipping Area of a Window


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:


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.PaintPicture Picture1.Picture, x, y
        y = y + 1
        For x = 1000 To 1 Step -1
            Picture2.PaintPicture Picture1.Picture, x, y
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... ;)

RE: Clipping Area of a Window

>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

RE: Clipping Area of a Window

>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:


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")
    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
        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...
    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

RE: Clipping Area of a Window

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...


RE: Clipping Area of a Window


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!

RE: Clipping Area of a Window

Thanks comaboy
The more code we see, the more ideas we can ingest.
- Ron

RE: Clipping Area of a Window

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

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