home |
the black hole's front page. all the latest vb rpg development and vbgaming news, as well as this week's feature rpg project! |
rpg projects
|
vb rpg projects under development by members of the bhC. show them your
support, and check out their games! |
message board |
a forum to interact with your fellow vb rpg programmers. you do *not* have
to be a bhC member to post! |
contact |
you want to contact the guy behind the black hole? here's where to
do it! |
|
|
 |
|
<< Back to Category List
Introduction to BitBlt - page 1 |
pages:
prev | 1 | next
Introduction to BitBlt
BitBlt is a member of the Windows API. It is used for copying an image from one object containing a DC (such as a form or a PictureBox) to another object containing a DC. To start things off, you will need to add a module to your project and insert the following code into it.
| 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
Public Const SRCCOPY = &HCC0020
Public Const SRCERASE = &H440328
Public Const SRCINVERT = &H660046
Public Const SRCPAINT = &HEE0086
Public Const SRCAND = &H8800C6
Now head back over to the Form. Rename it frmMain and set its ScaleMode to 3 (pixels). Create a PictureBox and name it picSource. Set its ScaleMode to 3 as well, and set its AutoRedraw property to True. Change the Picture of picSource to anything you want. Go back to the Form's code, and add the following to the picSource_Click procedure.
| Call BitBlt(frmMain.hDC, 0, 0, picSource.ScaleWidth, picSource.ScaleHeight, picSource.hDC, 0, 0, SRCCOPY)
You're probably thinking that this line looks like a mess. You're afraid that you'll never be able to learn to program games in Visual Basic!! Well don't worry, it's all quite simple! Here's an explanation of the values.
The first value, frmMain.hDC, refers to the destination. This is the DC of the object on which you would like to paste the image.
The following two values, both 0 (zero) in this case, represent the X- and Y-coordinate of where on the object you would like to paste the image. In this example, the image would be placed at (0, 0), or the top-left corner, of frmMain.
The picSource.ScaleWidth and picSource.ScaleHeight values represent the number of pixels horizontally and vertally to copy. You can change these values to numbers, too, such as 32 or 256.
The next value, picSource.hDC, refers to the source. This is the DC of the object from which you would like to copy the image.
The following two values, both 0 (zero) again, refer to the source coordinates to start copying from.
The final value, SRCCOPY, tells BitBlt that we just want to copy the image exactly as it appears in picSource.
|
Try running the program. When you click on the PictureBox (picSource) it will copy onto the top-left corner of the Form (frmMain)! Enjoy, and good luck!
| Matt Huggins
Nobis Productions
|