Creating bitmaps won't be used that often, in fact only once when creating the back buffer for drawing. Here the tBitmapInfo Type becomes handy because we don't have to put the created surface into the Bitmap() array. The function therefore is quite a stand-alone part of this Module, therefore we also have to take care about releasing created surfaces by hand.
Since the function is nothing more than some API calls I won't explain it at all, just take it as it is. However note that we set the MemoryDC property to true here so we can differ between loaded and created surfaces later.
Public Function CreateBitmap( iBitmapInfo as tBitmapInfo, iW as Long, iH as Long ) as Boolean On Error GoTo 1 With iBitmapInfo 'Set info .MemoryDC = True 'Create empty surface .DC = CreateCompatibleDC( MainWindow.hDC ) .CompatibleBitmap = CreateCompatibleBitmap( MainWindow.hDC, iW, iH ) .OriginalObject = SelectObject( .DC, .CompatibleBitmap ) End With 'Return true CreateBitmap = True Exit Function 1 'Error ReleaseBitmap iBitmapInfo 'Return error CreateBitmap = False End Function
Because we're just dealing with a tBitmapInfo here we don't have to get the file name and size, in fact it's not even available in this Type. Besides we're passing the requested width and height to this function so it wouldn't make any sense to get it back again.