|
-
Sep 8th, 2010, 03:39 PM
#1
Thread Starter
PowerPoster
[VB6 and API] - Convert a hdc to long variable
i build 1 function for convert hdc to long variable:
Code:
Public Function ConvertPicturetoLong(PicControl As PictureBox) As Long
Dim mdc As Long
Dim mBMP As Long
mdc = CreateCompatibleDC(PicControl.hDC)
mBMP = CreateCompatibleBitmap(PicControl.hDC, PicControl.ScaleWidth, PicControl.ScaleHeight)
SelectObject mdc, mBMP
ConvertPicturetoLong = mBMP
DeleteObject mBMP
DeleteDC mdc
End Function
but i belive that isn't work, because when i do:
Code:
dim s as long
s = ConvertPicturetoLong(PicAnimation(PicAnimation.Count - 1))
PicAnimation(PicAnimation.Count - 1).Picture = Nothing
Debug.Print BitBlt(PicAnimation(PicAnimation.Count - 1), 0, 0, UserControl.Width, UserControl.Height, s, 0, 0, vbSrcCopy)
because the bitblt() give me 0(zero). what isn't right?
-
Sep 9th, 2010, 09:54 AM
#2
Re: [VB6 and API] - Convert a hdc to long variable
In your function, you create a bitmap and select it into a dc, then delete the bitmap and the dc before the function exits. The bitmap is destroyed.
Besides, the variable you are returning did reference a Bitmap not an hDC. And you are using the return value as the source hDC parameter in the BitBlt call. BitBlt requires hDC handles not bitmap handles.
You are using your function to return an hDC for a BitBlt call, I think this is more correct
Code:
Public Function ConvertPicturetoLong(PicControl As PictureBox) As Long
ConvertPicturetoLong = PicControl.hDC
End Function
But you don't need a function, you can reference the picturebox directly.
-
Sep 9th, 2010, 11:26 AM
#3
Thread Starter
PowerPoster
Re: [VB6 and API] - Convert a hdc to long variable
 Originally Posted by LaVolpe
In your function, you create a bitmap and select it into a dc, then delete the bitmap and the dc before the function exits. The bitmap is destroyed.
Besides, the variable you are returning did reference a Bitmap not an hDC. And you are using the return value as the source hDC parameter in the BitBlt call. BitBlt requires hDC handles not bitmap handles.
You are using your function to return an hDC for a BitBlt call, I think this is more correct
Code:
Public Function ConvertPicturetoLong(PicControl As PictureBox) As Long
ConvertPicturetoLong = PicControl.hDC
End Function
But you don't need a function, you can reference the picturebox directly.
i lose the image before use the bitblt()
Code:
......
Dim s As Long
picGraphicsEffects.Picture = UserControl.Image
UserControl.Picture = Nothing
Load PicAnimation(PicAnimation.Count)
PrintWindow Extender.Container.hwnd, PicAnimation(PicAnimation.Count - 1).hDC, 0
PicAnimation(PicAnimation.Count - 1).Refresh
PicAnimation(PicAnimation.Count - 1).Picture = PicAnimation(PicAnimation.Count - 1).Image
s = PicAnimation(PicAnimation.Count - 1).hDC
PicAnimation(PicAnimation.Count - 1).Picture = Nothing
BitBlt PicAnimation(PicAnimation.Count - 1).hDC, 0, 0, UserControl.Width, UserControl.Height, s, Extender.Left, Extender.Top, vbSrcCopy ' has you see i use the variable long, but without sucess:(
PicAnimation(PicAnimation.Count - 1).Refresh
PicAnimation(PicAnimation.Count - 1).Picture = PicAnimation(PicAnimation.Count - 1).Image
TransparentAlphaBlendDIB picGraphicsEffects, PicAnimation(PicAnimation.Count - 1), CLng(m_Opacy), picGraphicsEffects.Point(0, 0)
UserControl.Picture = PicAnimation(PicAnimation.Count - 1).Image
Unload PicAnimation(PicAnimation.Count - 1)
................
why?
-
Sep 9th, 2010, 05:09 PM
#4
Re: [VB6 and API] - Convert a hdc to long variable
If the picturebox does not have AutoRedraw=True and is hidden/not visible, you should get just black I would think.
If the picturebox does have AutoRedraw=True and the size is smaller than what you are trying to Blt, you will get only the size of the picturebox, the rest should be black I would think
Now, if PicAnimation(picAnimation.Count-1).AutoRedraw=False, then this is a problem...
Code:
PrintWindow Extender.Container.hwnd, PicAnimation(PicAnimation.Count - 1).hDC, 0
PicAnimation(PicAnimation.Count - 1).Refresh ' << erased without AutoRedraw=True
If the above isn't the problem, I'm sure this is part of it too
Code:
PicAnimation(PicAnimation.Count - 1).Picture = PicAnimation(PicAnimation.Count - 1).Image
s = PicAnimation(PicAnimation.Count - 1).hDC
PicAnimation(PicAnimation.Count - 1).Picture = Nothing ' << erased DC
' ^^ if the AutoRedraw = True, the hDC changed, therefore s points to a destroyed hDC
It is never safe to cache a VB hDC since VB can change it whenever it wants. Try this example
-- add a picturebox to a form & paste this code. Run project & click the picturebox.
See the results. You may be surprised
Code:
Private Sub Picture1_Click()
Picture1.AutoRedraw = True
Picture1.PaintPicture Me.Icon, 0, 0
Debug.Print "hDC before setting picture to image: "; Picture1.hDC
Set Picture1.Picture = Picture1.Image
Debug.Print "hDC after setting picture to image: "; Picture1.hDC
Set Picture1.Picture = Nothing
Debug.Print "hDC after setting picture1.picture=nothing: "; Picture1.hDC
End Sub
Last edited by LaVolpe; Sep 9th, 2010 at 05:13 PM.
-
Sep 9th, 2010, 05:16 PM
#5
Thread Starter
PowerPoster
Re: [VB6 and API] - Convert a hdc to long variable
 Originally Posted by LaVolpe
If the picturebox does not have AutoRedraw=True and is hidden/not visible, you should get just black I would think.
If the picturebox does have AutoRedraw=True and the size is smaller than what you are trying to Blt, you will get only the size of the picturebox, the rest should be black I would think
Now, if PicAnimation(picAnimation.Count-1).AutoRedraw=False, then this is a problem...
Code:
PrintWindow Extender.Container.hwnd, PicAnimation(PicAnimation.Count - 1).hDC, 0
PicAnimation(PicAnimation.Count - 1).Refresh ' << erased without AutoRedraw=True
If the above isn't the problem, I'm sure this is part of it too
Code:
PicAnimation(PicAnimation.Count - 1).Picture = PicAnimation(PicAnimation.Count - 1).Image
s = PicAnimation(PicAnimation.Count - 1).hDC
PicAnimation(PicAnimation.Count - 1).Picture = Nothing ' << erased DC
' ^^ if the AutoRedraw = True, the hDC changed, therefore s points to a destroyed hDC
It is never safe to cache a VB hDC since VB can change it whenever it wants. Try this example
-- add a picturebox to a form & paste this code. Run project & click the picturebox.
See the results. You may be surprised
Code:
Private Sub Picture1_Click()
Picture1.AutoRedraw = True
Picture1.PaintPicture Me.Icon, 0, 0
Debug.Print "hDC before setting picture to image: "; Picture1.hDC
Set Picture1.Picture = Picture1.Image
Debug.Print "hDC after setting picture to image: "; Picture1.hDC
Set Picture1.Picture = Nothing
Debug.Print "hDC after setting picture1.picture=nothing: "; Picture1.hDC
End Sub
yes... the 3 values are diffent...
Can i put here my code by steps(because the real problem isn't with the post title)?
and yes the autoredraw is true and the scalemode is in pixels. and they are hidden.
Last edited by joaquim; Sep 9th, 2010 at 05:31 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|