I'm using VB6(SP6) on Windows XP.
I copied the sample code from:
http://support.microsoft.com/kb/147810
I quote the code is in full at the end of this post.
It demonstrates copying a bitmap using the BitBlt API function.
But my problem relates to syntax.
I placed two PictureBox controls (Picture1 and Picture2) on
Form1.
I assume that's what Microsoft intends when the article says
"Place two picture controls (Picture1 and Picture2) on Form1".
Note it doesn't say *PictureBox* controls; it says *Picture*
controls.
I put a bmp file in Picture1.
Microsoft's second code line:
Picture1.ScaleMode = PIXEL
generates the error "Method or data member not found.
(1) Why is this, please?
I've tried a number of workarounds, without success.
For example, I don't understand why this works:
Dim objP as PictureBox
For Each objP in Me.Controls
Debug.Print objP.ScaleMode
Next
The above code snippet indicates that it's possible to assign a
PictureBox control to a variable declared as of the PictureBox
class (as I expected).
But these don't work:
Dim objP as PictureBox
Set objP = Me!Picture1
Set objP = Me.Picture1
Set objP = Me.Controls("Picture1")
It seems that the right side of the equation returns a general
object, not a PictureBox control. I think this is the case after
testing with the TypeName function. It seems the general object
can't be assigned to the PictureBox variable. However, I
expected the right side of the equation to return a PictureBox
control.
(2) How should a PictureBox control be assigned to a variable
declared as of the PictureBox class?
CODE FROM:
http://support.microsoft.com/kb/147810
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As
Long, ByVal x _
As Long, ByVal y As Long, ByVal nWidth As Long, ByVal
nHeight As _
Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc
As _
Long, ByVal dwRop As Long) As Long
Private Sub Form_Click()
Const PIXEL = 3
Picture1.ScaleMode = PIXEL
Picture2.ScaleMode = PIXEL
hDestDC& = Picture2.hDC
x& = 0: y& = 0
nWidth& = Picture2.ScaleWidth
nHeight& = Picture2.ScaleHeight
' Assign information of the source bitmap.
hSrcDC& = Picture1.hDC
xSrc& = 0: ySrc& = 0
' Assign the SRCCOPY constant to the Raster operation.
dwRop& = &HCC0020
Suc& = BitBlt(hDestDC&, x&, y&, nWidth&, nHeight&, hSrcDC&, _
xSrc&, ySrc&, dwRop&)
End Sub
TIA
Geoff
> I copied the sample code from:
> http://support.microsoft.com/kb/147810
I just tried that sample and it ran with only a few editing problems.
> But my problem relates to syntax.
> I put a bmp file in Picture1.
>
> Microsoft's second code line:
>
> Picture1.ScaleMode = PIXEL
>
> generates the error "Method or data member not found.
>
> (1) Why is this, please?
It sounds like you've placed that code in the wrong module.
If there is a Picture1 control on the form, and that code is
pasted into the form's module, then there should be no error.
> But these don't work:
>
> Dim objP as PictureBox
> Set objP = Me!Picture1
> Set objP = Me.Picture1
> Set objP = Me.Controls("Picture1")
>
> (2) How should a PictureBox control be assigned to a variable
> declared as of the PictureBox class?
Again, you have to be sure you are in the right module, all those
methods should work, and I just tried them on my own system to
be sure....
LFS
As the code works for you, it seems to confirm I'm missing
something.
To confirm, yes, I have put the code in Form1's module. (The
left drop-down list box at the top of the VB editor shows Form1
and the controls on the form.)
When I type a period (full stop) after "Picture1.", Intellisense
show four properties: Count, Item, LBound, RBound. (Do you get
that?)
If I enter:
Picture1.Item(0). (note the last period or full stop)
Intellisense then shows all the expected properties of a
PictureBox, including ScaleMode.
However, using the Item property seems incorrect. It implies
that a PictureBox can contain a collection of images, which as
far as I know, it can't.
If I write:
Dim objPIC1 as PictureBox
Dim objPIC2 as PictureBox
Set objPIC1 = Me.Picture1.Item(0)
Set objPIC2 = Me.Picture2.Item(0)
I then get an error when instantiating objPIC2 because Picture2
doesn't yet contain an image.
Do you think Microsoft meant PictureBox, not Picture (if that
exists as a separate control)?
Any further thoughts Larry (or anyone)?
TIA
Geoff
"Larry Serflaten" <serf...@usinternet.com> wrote in message
news:OCbmh%23NhJH...@TK2MSFTNGP06.phx.gbl...
UBound, not RBound.
Geoff
"GeoffG" <geo...@nonospam.com> wrote in message
news:O61A88Qh...@TK2MSFTNGP05.phx.gbl...
> When I type a period (full stop) after "Picture1.", Intellisense
> show four properties: Count, Item, LBound, RBound. (Do you get
> that?)
That is a result of accessing a control array. If you had no array
you would get the normal methods and properties for the Picturebox.
The fix, remove Picture1 and Picture2 from the form, and add them
back, one at a time, do not copy and paste.... Depending on how
many controls you've added, you may have to remove more than two
pictureboxes. From the Properties drop down list, check for any
controls named Picture1(0) or Picture2(0) where 0 is any number.
eg: any of the form: Picture1(X) Select them from the list (so that
they are selected on the form) and then delete them from the form.
When you are done, there should be no controls named Picture1(X)
or Picture2(X) - then go ahead and add two Pictureboxes, one at a
time. VB should name them Picture1 and Picture2 automatically.....
> Do you think Microsoft meant PictureBox, not Picture (if that
> exists as a separate control)?
Yes, they said Picture control, which is (as you know) actually
called a PictureBox. The Picturebox is the correct control for
the example.
BltBlk is a fast API, but VB supports copying images on its own.
For an example, start a new project and paste the code below
into the form's module and run the program.
HTH
LFS
Private Sub Form_Paint()
Dim X&, Y&
For Y = 0 To Me.ScaleHeight Step 480
For X = 0 To Me.ScaleWidth Step 480
Me.PaintPicture Me.Icon, X, Y, 480, 480
Next X, Y
End Sub
I'm getting very rusty with VB! I'd narrowed the problem down to
control arrays - but hadn't yet solved the problem - when I got
your post. Only then, of course, I just about remembered I'd
come across control arrays in the dim, distant past. (The
batteries keeping those memories alive are almost exhausted!)
I realised that, with a Count property, I had to be looking at a
collection, and was baffled by the thought that it must be a
collection of images within the PictureBox. (It seems MS have
removed control arrays from VB 2008 - which I'm not into.)
The reason for exploring BitBlt() is I'm working through Steven
Roman's book "Win32 API Programming with Visual Basic". I'm
delving into Device Contexts, with the aim of helping a C
programmer friend eliminate screen flicker while drawing graphs.
Whether he has the patience to call API's remains to be seen!
I was pleased to get your painting example. No discernable
flicker there.
It's odd, but in all the time I've been using VBA, I've not come
across putting two variables on the same Next line, as in:
Next X, Y
Always something new to learn!
Very many thanks for taking time to help with this.
Regards.
Geoff.
"Larry Serflaten" <serf...@usinternet.com> wrote in message
news:%23iKGZfT...@TK2MSFTNGP02.phx.gbl...