home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / CODE_UPLOAD7459752000.psc / MemDC.bas < prev    next >
Encoding:
BASIC Source File  |  2000-07-05  |  2.4 KB  |  84 lines

  1. Attribute VB_Name = "DC"
  2. Option Explicit
  3.  
  4. 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
  5. Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
  6. Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
  7. Private Declare Function DeleteDC Lib "gdi32" (ByVal hdc As Long) As Long
  8. Private 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
  9. Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
  10.  
  11.  
  12. 'Constants for the GenerateDC function
  13. '**LoadImage Constants**
  14. Const IMAGE_BITMAP As Long = 0
  15. Const LR_LOADFROMFILE As Long = &H10
  16. Const LR_CREATEDIBSECTION As Long = &H2000
  17. Const LR_DEFAULTSIZE As Long = &H40
  18. '****************************************
  19.  
  20.  
  21.  
  22. 'IN: FileName: The file name of the graphics
  23. 'OUT: The Generated DC
  24. Public Function GenerateDC(FileName As String) As Long
  25. Dim DC As Long
  26. Dim hBitmap As Long
  27.  
  28. 'Create a Device Context, compatible with the screen
  29. DC = CreateCompatibleDC(0)
  30.  
  31. If DC < 1 Then
  32.     GenerateDC = 0
  33.     Exit Function
  34. End If
  35.  
  36. 'Load the image....BIG NOTE: This function is not supported under NT, there you can not
  37. 'specify the LR_LOADFROMFILE flag
  38.  
  39. hBitmap = LoadImage(0, FileName, IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE Or LR_LOADFROMFILE Or LR_CREATEDIBSECTION)
  40.  
  41. If hBitmap = 0 Then 'Failure in loading bitmap
  42.     DeleteDC DC
  43.     GenerateDC = 0
  44.     Exit Function
  45. End If
  46.  
  47. 'Throw the Bitmap into the Device Context
  48. SelectObject DC, hBitmap
  49.  
  50. 'Return the device context
  51. GenerateDC = DC
  52.  
  53. 'Delte the bitmap handle object
  54. DeleteObject hBitmap
  55.  
  56. End Function
  57. 'Deletes a generated DC
  58. Public Function DeleteGeneratedDC(DC As Long) As Long
  59.  
  60. If DC > 0 Then
  61.     DeleteGeneratedDC = DeleteDC(DC)
  62. Else
  63.     DeleteGeneratedDC = 0
  64. End If
  65.  
  66. End Function
  67.  
  68.  
  69.  
  70. '''''Use for cleanup when generating DC's
  71. 'If DCSprite <= 0 Then
  72. '    MsgBox "Failure in creating sprite dc"
  73.     'Clean up after the created mask
  74. '    DeleteGeneratedDC DCMask
  75. 'End If
  76.  
  77.  
  78. '''''''''''''''''CLEANUP''''''''''''''''''''
  79. 'DeleteGeneratedDC DCMask
  80. 'DeleteGeneratedDC DCSprite
  81.  
  82. 'Unload Me
  83. 'Set frmMemoryDC = Nothing
  84.