Gaming_World
Aug 8th, 2002, 10:59 PM
I am attempting to use memory DCs in a game I am writting, but all the DC ever contains is blank. Heres my code:
Public Function GenerateDC(FileName As String) As Long
Dim DC&, hBitmap&
'Create a Device Context, compatible with the screen
DC = CreateCompatibleDC(0)
If DC < 1 Then 'Check for errors, if there was one, exit the function
GenerateDC = 0
Exit Function
End If
'Load the image....
hBitmap = LoadImage(0, FileName, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE Or LR_CREATEDIBSECTION)
If hBitmap = 0 Then 'Failure in loading bitmap
DeleteDC DC
GenerateDC = 0
Exit Function
End If
'Assign the Bitmap to the Device Context
SelectObject DC, hBitmap
'Return the device context
GenerateDC = DC
'Delete the bitmap handle object
DeleteObject hBitmap
End Function
Public Function DeleteGeneratedDC(DC As Long) As Long
If DC > 0 Then 'Check if a vailid DC was sent (greater then 0)
DeleteGeneratedDC = DeleteDC(DC)
Else
DeleteGeneratedDC = 0
End If
End Function
Public Sub LoadGraphics()
Dim lngCurrDC&, lngTempDC&, strTmpFileN$
Dim Width&, Height&, FNum%, tmpS$, tmpA$(), X&, Y&
strTmpFileN = GetTemporaryFilename
FNum = FreeFile
'Cities
Cities = GenerateDC(AppFolder & GraphicsFolder & "\Cities" & GraphicsExt)
BitBlt frmMain.Picture1.hdc, 0, 0, 675, 648, Cities, 0, 0, vbSrcCopy
frmMain.Picture1.Refresh
End Sub
Public Function GenerateDC(FileName As String) As Long
Dim DC&, hBitmap&
'Create a Device Context, compatible with the screen
DC = CreateCompatibleDC(0)
If DC < 1 Then 'Check for errors, if there was one, exit the function
GenerateDC = 0
Exit Function
End If
'Load the image....
hBitmap = LoadImage(0, FileName, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE Or LR_CREATEDIBSECTION)
If hBitmap = 0 Then 'Failure in loading bitmap
DeleteDC DC
GenerateDC = 0
Exit Function
End If
'Assign the Bitmap to the Device Context
SelectObject DC, hBitmap
'Return the device context
GenerateDC = DC
'Delete the bitmap handle object
DeleteObject hBitmap
End Function
Public Function DeleteGeneratedDC(DC As Long) As Long
If DC > 0 Then 'Check if a vailid DC was sent (greater then 0)
DeleteGeneratedDC = DeleteDC(DC)
Else
DeleteGeneratedDC = 0
End If
End Function
Public Sub LoadGraphics()
Dim lngCurrDC&, lngTempDC&, strTmpFileN$
Dim Width&, Height&, FNum%, tmpS$, tmpA$(), X&, Y&
strTmpFileN = GetTemporaryFilename
FNum = FreeFile
'Cities
Cities = GenerateDC(AppFolder & GraphicsFolder & "\Cities" & GraphicsExt)
BitBlt frmMain.Picture1.hdc, 0, 0, 675, 648, Cities, 0, 0, vbSrcCopy
frmMain.Picture1.Refresh
End Sub