VB Code:
'// How to use BitBlt
Dim RC '// RC stands for Return Code.
'// Usually it doesn't matter (we can just throw it away), but it's useful if it doesn't work!
'// Prototype
'// RC = BitBlt([i]Destination[/i], [i]X Value (horizontal)[/i], [i]Y Value (vertical)[/i], [i]Width[/i], [i]Height[/i], [i]Source[/i], [i]X Value of Source (where to start getting data from horizontally), [i]Y Value of Source (where to start getting data from vertically)[/i], [i]How to Copy[/i])
'// Source and Destination are found by using the .hDC properties of pictureboxes, or just by offscreen device contexts (that's what DC stands for, the h stands for a handle, so it's a handle to a device context).
'// All Width, Y, X, etc. properties are in PIXELS. Remember to set your picturebox's ScaleMode property to 3 (pixels).
'// How to Copy: There are pre-defined constants starting with VB5 (I think) for the copy modes: SrcCopy (copy source bits to destination), SrcAnd (AND source bits with destination), SrcPaint, etc. SrcCopy is used for normal blits, SrcAnd/SrcPaint/MergePaint are used for transparent blitting (eg. mask is used to determine transparency).
'// Now, let's use this:
RC = BitBlt(PicOut.hDC, 0, 0, 200, 200, PicIn(0).hDC, 0, 0, vbSrcCopy)
'// This copies PicIn(0) onto PicOut at (0, 0) with a width and height of both 200 (you can also use PicIn(0).ScaleWidth, PicIn(0).ScaleHeight, etc.). It also uses the COPY constant to make the bits there equal the bits on the source (ex. no transformation).
'// You can also use AutoRedraw = True on all of the pictureboxes, and make them invisible.
With PicOut
.AutoRedraw = True
.Visible = False
End With
With PicIn(0)
.AutoRedraw = True
.Visible = False
End With
RC = BitBlt(PicOut.hDC, 0, 0, 200, 200, PicIn(0).hDC, 0, 0, vbSrcCopy)
[b]PicOut.Refresh[/b]
'// You must use ***.Refresh to actually update the screen with the new picture. This allows games that use BitBlt (or other GDI calls) to wait until a monitor sync to draw, and also to make flicker-free drawing. If you didn't have autoredraw, you'd see the screen clearing and everything being drawn. With this you can make it show only when everything's already drawn.
Next post I'll show how to use OffScreen DCs! Make sure to use the API Viewer to get the BitBlt API Declaration, as well.