Attribute VB_Name = "modApi"
Option Explicit



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 Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Public Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
Public Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject 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 GetObjectAPI Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) 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 Declare Function GetTickCount Lib "kernel32" () As Long
Public Declare Function StretchBlt Lib "gdi32" (ByVal hdc 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 nSrcWidth As Long, ByVal nSrcHeight As Long, ByVal dwRop As Long) As Long
Public Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
Public Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long

Public Type MoB
    x As Long
    y As Long
    OldX As Long
    OldY As Long
    Direction As Long
    Movement As Integer
    Moved As Boolean
End Type

Public Type BITMAP
    bmType As Long
    bmWidth As Long
    bmHeight As Long
    bmWidthBytes As Long
    bmPlanes As Integer
    bmBitsPixel As Integer
    bmBits As Long
End Type

Public Const SRCAND = &H8800C6
Public Const SRCPAINT = &HEE0086
Public Const SRCCOPY = &HCC0020

Public Const GM_CONTROL = &H11
Public Const GM_DOWN = &H28
Public Const GM_ESCAPE = &H1B
Public Const GM_LEFT = &H25
Public Const GM_RIGHT = &H27
Public Const GM_UP = &H26
Public Const GM_SPACE = &H20


Public Const IMAGE_BITMAP As Long = 0
Public Const LR_LOADFROMFILE As Long = &H10
Public Const LR_CREATEDIBSECTION As Long = &H2000







Public Function GenerateDC(ByVal FileName As String, BitmapProperties As BITMAP) As Long
    Dim DC As Long
    Dim hBitmap As Long
    DC = CreateCompatibleDC(0)



    hBitmap = LoadImage(0, FileName, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE Or LR_CREATEDIBSECTION)


    If hBitmap = 0 Then
        DeleteDC DC
        GenerateDC = 0
        MsgBox "Error Loading File!"
        Exit Function
    End If
    GetObjectAPI hBitmap, Len(BitmapProperties), BitmapProperties


    SelectObject DC, hBitmap
        GenerateDC = DC
        DeleteObject hBitmap
End Function

Public Function NewDC(hdcScreen As Long, HorRes As Long, VerRes As Long) As Long
  Dim hdcCompatible As Long
  Dim hbmScreen As Long
  hdcCompatible = CreateCompatibleDC(hdcScreen)
  hbmScreen = CreateCompatibleBitmap(hdcScreen, HorRes, VerRes)
  If SelectObject(hdcCompatible, hbmScreen) = vbNull Then
    NewDC = 1
  Else
    NewDC = hdcCompatible
  End If
  DeleteDC (hdcScreen)
End Function




