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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Clipping Area of a Window

Status
Not open for further replies.

RMS001

Programmer
Nov 12, 2002
45
0
0
CA
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
 
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... ;)
 
>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
 
>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:
[blue]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
[/blue]
 
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
 
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!
 
Thanks comaboy
The more code we see, the more ideas we can ingest.
- Ron
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top