cmemdc.cls

来自「VB中实现3层结构的完整教学示例(很难得的)」· CLS 代码 · 共 49 行

CLS
49
字号
VERSION 1.0 CLASS
Begin
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
End
Attribute VB_Name = "cMemDC"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
Private m_hDC As Long
Private m_hBmpOld As Long
Private m_hBmp As Long

Public Property Get hDC() As Long
    hDC = m_hDC
End Property

Public Sub Create(ByVal width As Long, ByVal height As Long)
    Dim lhDC As Long
    Class_Terminate
    lhDC = CreateDCAsNull("DISPLAY", ByVal 0&, ByVal 0&, ByVal 0&)
    m_hDC = CreateCompatibleDC(lhDC)
    m_hBmp = CreateCompatibleBitmap(lhDC, width, height)
    m_hBmpOld = SelectObject(m_hDC, m_hBmp)
    If m_hBmpOld = 0 Then Class_Terminate
    DeleteDC lhDC
End Sub

Private Sub Class_Terminate()
    If Not m_hBmpOld = 0 Then
        SelectObject m_hDC, m_hBmpOld
        m_hBmpOld = 0
    End If
    If Not m_hBmp = 0 Then
        DeleteObject m_hBmp
        m_hBmp = 0
    End If
    If Not m_hDC = 0 Then
        DeleteDC m_hDC
        m_hDC = 0
    End If
End Sub

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?