home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 5_2007-2008.ISO / data / Zips / eMe_ID_Car2055213222007.psc / cDIBSectionmod.cls < prev    next >
Text File  |  2006-07-09  |  6KB  |  181 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4.   Persistable = 0  'NotPersistable
  5.   DataBindingBehavior = 0  'vbNone
  6.   DataSourceBehavior  = 0  'vbNone
  7.   MTSTransactionMode  = 0  'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "cDIBSection"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = False
  14. Option Explicit
  15. ' ==================================================================================
  16. ' Requires:    mIJLmod.cls
  17. '              ijl15.dll (Intel)
  18. ' ==================================================================================
  19.  
  20. Private Type RGBQUAD
  21.     rgbBlue As Byte
  22.     rgbGreen As Byte
  23.     rgbRed As Byte
  24.     rgbReserved As Byte
  25. End Type
  26. Private Type BITMAPINFOHEADER '40 bytes
  27.     biSize As Long
  28.     biWidth As Long
  29.     biHeight As Long
  30.     biPlanes As Integer
  31.     biBitCount As Integer
  32.     biCompression As Long
  33.     biSizeImage As Long
  34.     biXPelsPerMeter As Long
  35.     biYPelsPerMeter As Long
  36.     biClrUsed As Long
  37.     biClrImportant As Long
  38. End Type
  39. Private Type BITMAPINFO
  40.     bmiHeader As BITMAPINFOHEADER
  41.     bmiColors As RGBQUAD
  42. End Type
  43. Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hDc As Long) As Long
  44. Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
  45.  
  46. Private Declare Function GetDesktopWindow Lib "user32" () As Long
  47. Private Declare Function CreateDIBSection Lib "gdi32" _
  48.     (ByVal hDc As Long, _
  49.     pBitmapInfo As BITMAPINFO, _
  50.     ByVal un As Long, _
  51.     lplpVoid As Long, _
  52.     ByVal handle As Long, _
  53.     ByVal dw As Long) As Long
  54. Private 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
  55. Private Declare Function SelectObject Lib "gdi32" (ByVal hDc As Long, ByVal hObject As Long) As Long
  56. Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
  57. Private Declare Function DeleteDC Lib "gdi32" (ByVal hDc As Long) As Long
  58. Private Const BI_RGB = 0&
  59. Private Const BI_RLE4 = 2&
  60. Private Const BI_RLE8 = 1&
  61. Private Const DIB_RGB_COLORS = 0 '  color table in RGBs
  62. Private Type BITMAP
  63.     bmType As Long
  64.     bmWidth As Long
  65.     bmHeight As Long
  66.     bmWidthBytes As Long
  67.     bmPlanes As Integer
  68.     bmBitsPixel As Integer
  69.     bmBits As Long
  70. End Type
  71. Private Declare Function GetObjectAPI Lib "gdi32" Alias "GetObjectA" (ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long
  72.  
  73. ' Handle to the current DIBSection:
  74. Private m_hDIb As Long
  75. ' Handle to the old bitmap in the DC, for clear up:
  76. Private m_hBmpOld As Long
  77. ' Handle to the Device context holding the DIBSection:
  78. Private m_hDC As Long
  79. ' Address of memory pointing to the DIBSection's bits:
  80. Private m_lPtr As Long
  81. ' Type containing the Bitmap information:
  82. Private m_tBI As BITMAPINFO
  83. Public Property Get BytesPerScanLine() As Long
  84.     ' Scans must align on dword boundaries:
  85.     BytesPerScanLine = (m_tBI.bmiHeader.biWidth * 3 + 3) And &HFFFFFFFC
  86. End Property
  87. Public Property Get Width() As Long
  88.     Width = m_tBI.bmiHeader.biWidth
  89. End Property
  90. Public Property Get Height() As Long
  91.     Height = m_tBI.bmiHeader.biHeight
  92. End Property
  93. Public Sub LoadPictureBlt( _
  94.         ByVal lhDC As Long, _
  95.         Optional ByVal lSrcLeft As Long = 0, _
  96.         Optional ByVal lSrcTop As Long = 0, _
  97.         Optional ByVal lSrcWidth As Long = -1, _
  98.         Optional ByVal lSrcHeight As Long = -1, _
  99.         Optional ByVal eRop As RasterOpConstants = vbSrcCopy _
  100.     )
  101.     If lSrcWidth < 0 Then lSrcWidth = m_tBI.bmiHeader.biWidth
  102.     If lSrcHeight < 0 Then lSrcHeight = m_tBI.bmiHeader.biHeight
  103.     BitBlt m_hDC, 0, 0, lSrcWidth, lSrcHeight, lhDC, lSrcLeft, lSrcTop, eRop
  104. End Sub
  105. Public Property Get DIBSectionBitsPtr() As Long
  106.     DIBSectionBitsPtr = m_lPtr
  107. End Property
  108. Public Sub ClearUp()
  109.     If (m_hDC <> 0) Then
  110.         If (m_hDIb <> 0) Then
  111.             SelectObject m_hDC, m_hBmpOld
  112.             DeleteObject m_hDIb
  113.         End If
  114.         DeleteObject m_hDC
  115.     End If
  116.     m_hDC = 0: m_hDIb = 0: m_hBmpOld = 0: m_lPtr = 0
  117. End Sub
  118. Public Function CreateFromPicture( _
  119.         ByRef picThis As StdPicture _
  120.     )
  121. Dim lhDC As Long
  122. Dim lhDCDesktop As Long
  123. Dim lhBmpOld As Long
  124. Dim tBMP As BITMAP
  125.     
  126.     GetObjectAPI picThis.handle, Len(tBMP), tBMP
  127.     If (Create(tBMP.bmWidth, tBMP.bmHeight)) Then
  128.         lhDCDesktop = GetDC(GetDesktopWindow())
  129.         If (lhDCDesktop <> 0) Then
  130.             lhDC = CreateCompatibleDC(lhDCDesktop)
  131.             DeleteDC lhDCDesktop
  132.             If (lhDC <> 0) Then
  133.                 lhBmpOld = SelectObject(lhDC, picThis.handle)
  134.                 LoadPictureBlt lhDC
  135.                 SelectObject lhDC, lhBmpOld
  136.                 DeleteObject lhDC
  137.             End If
  138.         End If
  139.     End If
  140. End Function
  141. Public Function CreateDIB( _
  142.         ByVal lhDC As Long, _
  143.         ByVal lWidth As Long, _
  144.         ByVal lHeight As Long, _
  145.         ByRef hDib As Long _
  146.     ) As Boolean
  147.     With m_tBI.bmiHeader
  148.         .biSize = Len(m_tBI.bmiHeader)
  149.         .biWidth = lWidth
  150.         .biHeight = lHeight
  151.         .biPlanes = 1
  152.         .biBitCount = 24
  153.         .biCompression = BI_RGB
  154.         .biSizeImage = BytesPerScanLine * .biHeight
  155.     End With
  156.     hDib = CreateDIBSection( _
  157.             lhDC, _
  158.             m_tBI, _
  159.             DIB_RGB_COLORS, _
  160.             m_lPtr, _
  161.             0, 0)
  162.     CreateDIB = (hDib <> 0)
  163. End Function
  164. Public Function Create( _
  165.         ByVal lWidth As Long, _
  166.         ByVal lHeight As Long _
  167.     ) As Boolean
  168.     ClearUp
  169.     m_hDC = CreateCompatibleDC(0)
  170.     If (m_hDC <> 0) Then
  171.         If (CreateDIB(m_hDC, lWidth, lHeight, m_hDIb)) Then
  172.             m_hBmpOld = SelectObject(m_hDC, m_hDIb)
  173.             Create = True
  174.         Else
  175.             DeleteObject m_hDC
  176.             m_hDC = 0
  177.         End If
  178.     End If
  179. End Function
  180.  
  181.