Public Declare Function BitBlt Lib "gdi32" (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
Public Const SRCCOPY = &HCC0020
Public Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
Public Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
Public Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Public Declare Function LoadImage Lib "user32" Alias "LoadImageA" (ByVal hInst As Long, ByVal lpsz As String, ByVal un1 As Long, ByVal n1 As Long, ByVal n2 As Long, ByVal un2 As Long) As Long
Public Const IMAGE_BITMAP = 0
Public Const LR_LOADFROMFILE = &H10
Public Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Public Function LoadGraphics(ByVal FileName As String, ByVal PosX As Long, ByVal PosY As Long, ByVal Width As Long, ByVal Height As Long, ControlName As Object)
On Error GoTo ErrHandler 'Cheap error handling that message boxes the errors.
Dim DC As Long 'Hold the device context of the image
Dim Image As Long 'Holds the loaded image
Dim NewTile As Integer 'The control # to use
NewTile = ControlName.Count 'Get the count of present pictureboxes
Load ControlName(NewTile) 'Load one more Picturebox in the control array
'ControlName(NewTile).Visible = True 'Make the PB visible (TESTING PURPOSES)
'ControlName(NewTile).Move ControlName(NewTile - 1).Left + (Width * Screen.TwipsPerPixelX), ControlName(NewTile - 1).Top + (Height * Screen.TwipsPerPixelY), Width * Screen.TwipsPerPixelX, Height * Screen.TwipsPerPixelY 'Move the picturebox (TESTING PURPOSES)
'FileName = App.Path & "\Maps\" & FileName 'Use this line if you only want graphics to be within the app's directory
DC = CreateCompatibleDC(ControlName(NewTile).hdc) 'Create a Device Contect compatible with the PictureBox
Image = LoadImage(0, FileName, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE) 'Load the entire image file
Call SelectObject(DC, Image) 'Assign the image to the device context
Call BitBlt(ControlName(NewTile).hdc, 0, 0, Width, Height, DC, PosX, PosY, SRCCOPY) 'Copy the specified section of the bitmap into the picturebox
'Clean up our tracks
DeleteDC DC
DeleteObject Image
Exit Function 'Exit function without launching the error handler
ErrHandler:
MsgBox Err.Number & Err.Description
End Function