Need Help: Problem with StrechBlt() 
Author Message
 Need Help: Problem with StrechBlt()

Hello All

Need some help with the StrechBlt function.

I have a Form with a picture box and 2 labels on the picture box and 2
timer controls. The scale mode for Picture and Form is Twips (i'm too
far in the project now, that i don't want to change it to Pixels)

The program basically moves the 2 label control bottom to top and the
caption of the labels changes every few seconds. All is fine.

The problem is, the windowstate for my Form is Maximised, but the image
in the picture box dosen't strech. In the Form Resize event i use the
StrechBlt API, to paint the form with the Picture box's image.Since the
API's take only pixels, i first set both the Form and the Picture
Control Scalemode to Pixels, then call the StrechBlt and in the Form
Activate i set the scalemode back to Twips.

What would be the problem...can some one tell me how to maximise the
picture control to the form's size, without having to change the
Saclemode to Pixels for Picture control and Form...i know that
Twipsperpixelx will convert, but don't know how to use it...can someone
please shed some light..would appreciate a cc to

Thanks
Sue

Sent via Deja.com http://www.*-*-*.com/
Before you buy.



Tue, 27 May 2003 03:00:00 GMT  
 Need Help: Problem with StrechBlt()

writes

Quote:
>The problem is, the windowstate for my Form is Maximised, but the image
>in the picture box dosen't strech. In the Form Resize event i use the
>StrechBlt API, to paint the form with the Picture box's image.Since the
>API's take only pixels, i first set both the Form and the Picture
>Control Scalemode to Pixels, then call the StrechBlt and in the Form
>Activate i set the scalemode back to Twips.

The StretchBlt Function doesn't care about the ScaleMode of
source/destination, only that its params are in logical units which, in
this case, are Pixels.

As an alternative to changing ScaleMode, or using TwipsPerPixelX/Y, you
can use the ScaleX/Y Functions for conversions between modes. You can
convert to Pixels (or any other mode) irrespective of what the ScaleMode
actually is.

For the Form:
 ScaleX(Me.ScaleWidth, Me.ScaleMode, vbPixels)
 ScaleY(Me.ScaleHeight, Me.ScaleMode, vbPixels)

For the PictureBox:
 ScaleX(Picture1.ScaleWidth, Picture1.ScaleMode, vbPixels)
 ScaleY(Picture1.ScaleHeight, Picture1.ScaleMode, vbPixels)

So, if your Form and PictureBox are in Twips and you stretch from the
PictureBox Image to Form:

  lret = StretchBlt(Me.hdc, _
      0, 0, _
      ScaleX(Me.ScaleWidth, Me.ScaleMode, vbPixels), _
      ScaleY(Me.ScaleHeight, Me.ScaleMode, vbPixels), _
      Picture1.hdc, _
      0, 0, _
      ScaleX(Picture1.ScaleWidth, Picture1.ScaleMode, vbPixels), _
      ScaleY(Picture1.ScaleHeight, Picture1.ScaleMode, vbPixels), _
      vbSrcCopy)

Setting ScaleModes to Pixels from the start is usually less tedious.

Quote:
>What would be the problem...can some one tell me how to maximise the
>picture control to the form's size, without having to change the
>Saclemode to Pixels for Picture control and Form...i know that
>Twipsperpixelx will convert, but don't know how to use it...can someone
>please shed some light..

What your actually saying here "maximise the picture control to the
form's size" means to physically resize the Picture Box so I'm not sure
what you're asking.

--
Richard Mason



Tue, 27 May 2003 20:20:34 GMT  
 Need Help: Problem with StrechBlt()
Hi Mike

This morning I sent you an email with the attachments so you could see
where iam going wrong..hope you got it..

All I need is to know how to strech the image by 30% using the
StrechBlt function

Thanks for all your help

Sue..



Quote:
> > Need some help with the StrechBlt function.

> > I have a Form with a picture box and 2 labels on the picture box
and 2
> > timer controls. The scale mode for Picture and Form is Twips (i'm
too
> > far in the project now, that i don't want to change it to Pixels)

> > The program basically moves the 2 label control bottom to top and
the
> > caption of the labels changes every few seconds. All is fine.

> > The problem is, the windowstate for my Form is Maximised, but the
image
> > in the picture box dosen't strech. In the Form Resize event i use
the
> > StrechBlt API, to paint the form with the Picture box's image.Since
the
> > API's take only pixels, i first set both the Form and the Picture
> > Control Scalemode to Pixels, then call the StrechBlt and in the Form
> > Activate i set the scalemode back to Twips.

> > What would be the problem...can some one tell me how to maximise the
> > picture control to the form's size, without having to change the
> > Saclemode to Pixels for Picture control and Form...i know that
> > Twipsperpixelx will convert, but don't know how to use it...can
someone
> > please shed some light..would appreciate a cc to

> Sorry, I've not got back to your e-mail about this yet, guess you
finally
> gave up waiting? ;)
> Stick this chunk of code at the bottom of Form_Load() beneath the
other two
> lines I told you to put there previously.

> '*** START CUT ***'

>     Form1.AutoRedraw = True
>     Picture1.Visible = False
>     With Screen
>         Form1.Move 0, 0, .Width, .Height
>         DoEvents 'The form is not maximised yet
>         StretchBlt Form1.hdc, 0, 0, _
>             .Width \ .TwipsPerPixelX, _
>             .Height \ .TwipsPerPixelY, _
>             Picture1.hdc, 0, 0, _
>             Picture1.Width \ .TwipsPerPixelX, _
>             Picture1.Height \ .TwipsPerPixelY, _
>             vbSrcCopy
>     End With
>     Form1.Refresh

> '*** END CUT ***'

> However, this screws up your animation since your not drawing on the
picture
> box any more.  Converting the code to draw on the form rather than the
> picture box by changing the With statement in the timer doesn't work
because
> you have to clear the old frame and firing .Cls off at a form and this
> doesn't work when the ScaleMode is twips.  In fact if you've not got
a great
> deal of memory you may simply get a "Can't create AutoRedraw image"
at this
> point, it's really best not to set a form set to AutoRedraw with a
ScaleMode
> of twips.
> In all honesty though, if I were you I'd just convert the application
to use
> a ScaleMode of pixels.  There's not very much code that's dependant
on the
> scale mode only Timer1 as far as I can see.  If you want a quick want
of
> converting your code to pixels then simply divide all your offsets by
15,
> that's what TwipsPerPixelX/Y stand for in most cases.
> If you need more help on converting the code then let me know.
> Hope this helps,

>     Mike

>  -- EDais --

> WWW: Http://Members.xoom.com/EDais/



Sent via Deja.com http://www.deja.com/
Before you buy.


Wed, 28 May 2003 00:32:36 GMT  
 Need Help: Problem with StrechBlt()

Quote:
> This morning I sent you an email with the attachments so you could see
> where iam going wrong..hope you got it..

Yeah, I got it and sent you back a version.  I presume that went through ok?

Quote:
> All I need is to know how to strech the image by 30% using the
> StrechBlt function

Not necessarily, there's lots of screen sizes, you mentioned 640*480 and
800*600, but the machines here for instance run at 1280*1024 or 1600*1200.
There's also lots of weird sizes for things such as wide-screen monitors and
such which you have to watch out for sometimes.  The code I sent you will
just re-scale the picture box image to fill the entire screen and run the
animation accordingly, no matter what screen res your running at.

Quote:
> Thanks for all your help

No problem, let me know if you got the code spliced ok.

    Mike

 -- EDais --

WWW: Http://Members.xoom.com/EDais/




Thu, 29 May 2003 11:13:37 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Need help with StrechBlt

2. *** HELP *** Is StrechBlt working for 256 colors stretching ?

3. I need help with a datediff problem ( a fairly new user who needs help)

4. Advanced StrechBlt / DIB question (using vbAccelerator's cDIBSection class)

5. Printing Bitmap with StrechBlt in VB 3.0

6. Print Bitmap with Strechblt in VB 3.0

7. MSGraph 97 - need a reference - and need help with problems

8. Need help with Distribution/installation problem problem

9. HELP - Newbie needs help on simple problem!

10. HELP!!! NEED HElp: problem with ado

11. {Need Help Big Project Need Help}

12. need need help help (911)!!!!!

 

 
Powered by phpBB® Forum Software