DirectX SDK |
This section pertains only to application development in Visual Basic. See DirectDraw C/C++ Tutorials.
So far in the Tutorial 1: Blitting to the Screen sample you have created a primary surface and a off-screen surface which has a loaded bitmap. To display the bitmap on the screen, you must blit the off-screen surface to the primary surface. The blit method of the DirectDraw surface object takes four arguments and returns a Long indicating the success or failure of the blit. Two of the arguments of are type RECT which specify the bounding rectangles of the destination surface and the source surface.
The coordinates of the source rectangle are obtained from the lHeight and the lWidth members of the off-screen surface description. There are a few extra steps in obtaining the destination rectangle. First of all, since Visual Basic uses twips for screen measurement and DirectX uses pixels, the dimensions of the Visual Basic picture box control must be converted to pixels before setting the destination rectangle. This is accomplished by setting the ScaleMode property of the form to Pixels and then making the width and height of the picture box equal to the ScaleWidth and ScaleHeight of the form. Note: the width and height of the form stay in twips after you change the ScaleMode, but the ScaleWidth and the ScaleHeight are now in pixels. In the Tutorial 1 blitting sample, this is done with the statements:
Picture1.Width = Me.ScaleWidth Picture1.Height = Me.ScaleHeight
These statements are in the Form_Resize event and are executed when the form is initially displayed and resized.
Furthermore, the destination RECT type is filled when the DirectX7.GetWindowRect is called.
Lastly the blit is perform with the blt method of the primary surface object:
ddrval = objDDPrimSurf.blt(r1, objDDSurf, r2, DDBLT_WAIT)
The result of the method is a Long that is stored in ddrval. You can check this variable for success or failure. The last argument of the method is the DDBLT_WAIT flag which tells DirectDraw to wait if the blitter is busy and blit the surface when it becomes available.