VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "clsDC"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit

' Name:      Create a DC for drawing operations
' Author:    Powersoft Programming
' Email:     webmaster@psprogramming.virtualave.net
' Internet:  http://psprogramming.virtualave.net/

' Credits to:
'     Fox McCloud (http://orion.spaceports.com/~mccloud/)
'       ...for providing the DC tutorial at
'          http://orion.spaceports.com/~mccloud/english/coding/tutorial/3.3.html

' Properties
Private p_hDC As Long
Private p_lWidth As Long
Private p_lHeight As Long
Private p_pPicture As StdPicture

' API Declarations
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal hWnd As Long, ByVal hdc As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
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
Public Sub BltAll(hDest As Long, XDest As Long, YDest As Long, hROP As RasterOpConstants)
    ' Blit the complete image to the destination DC
    Call BitBlt(hDest, XDest, YDest, p_lWidth, p_lHeight, p_hDC, 0, 0, hROP)
End Sub

Public Sub BltPart(hDest As Long, XDest As Long, YDest As Long, XSrc As Long, YSrc As Long, SrcWidth As Long, SrcHeight As Long, hROP As RasterOpConstants)
    ' Blit part of the image to the destination DC
    Call BitBlt(hDest, XDest, YDest, SrcWidth, SrcHeight, p_hDC, XSrc, YSrc, hROP)
End Sub


Public Function CreateDC(hCompatible As Long) As Boolean
    ' Create a compatible DC
    p_hDC = CreateCompatibleDC(hCompatible)
    
    If p_hDC > 0 Then
        ' Success
        CreateDC = True
    Else
        ' Error
        CreateDC = False
    End If
End Function


Public Sub DestroyDC(hWnd As Long)
    ' Release the DC
    Call ReleaseDC(hWnd, p_hDC)
End Sub


Public Property Get Picture() As StdPicture
    ' Return the picture
    Set Picture = p_pPicture
End Property

Public Property Set Picture(Value As StdPicture)
    ' Set the picture
    Set p_pPicture = Value
    
    ' Store the dimensions (in pixels)
    p_lWidth = p_pPicture.Width / Screen.TwipsPerPixelX
    p_lHeight = p_pPicture.Height / Screen.TwipsPerPixelY
    
    ' Select the picture into the DC
    Call SelectObject(p_hDC, p_pPicture)
End Property
Public Property Get Width() As Long
    ' Return the width
    Width = p_lWidth
End Property


Public Property Get Height() As Long
    ' Return the height
    Height = p_lHeight
End Property

Private Sub Class_Terminate()
    ' Destroy the picture
    Call DeleteObject(p_pPicture)
    Set p_pPicture = Nothing
End Sub


