at this point you can really impress your family and friends by using words like hdc, dwrop and bitblt in casual conversation and are likely to be the life of the party but if your goal is to actually write a game we'll need to go on. let's try a simple project to see how this all works.
this sample project demonstrates the use of the bitblt function to draw a bitmap from a picturebox to a form. this sample project is found in bitblttest.zip .
in the project we have a form (frmbitblt), a picturebox with a small picture (picbitblt) and a command button (cmdbitblt).
note: since the bitblt function expects the parameters to be in pixels, the scalemode property of the picturebox and the form has been changed from 1-twips to 3-pixels.
the code for this small program is very simple:
option explicit
declare function bitblt lib "gdi32" alias "bitblt" _
(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 cmdbitblt_click()me.cls
bitblt me.hdc, 0, 0, picbitblt.scalewidth, _
picbitblt.scaleheight, picbitblt.hdc, 0, 0, vbsrccopyend sub
when the button is clicked, the bitblt function is called to draw the picture of the picbitblt picture box onto the form. we specify the hdestdc parameter of the bitblt function to be that of the current form (me.hdc). then we specify the upper left x and y coordinates of the destination to be 0. the width and height of the picture on the destination is defined to be the scalewidth and scaleheight of the picture box. this ensures that we will not be copying the border of the picture box, but only the elements inside the picture box. the hsrcdc is set to the source hdc, which is of course the picbitblt picturebox. we specify that the drawing should start at 0,0. the width and height of the source will then be the same as the width and height of the destination area.
press the command button and observe how the picture is drawn onto the form.