forked from lee-soft/ViPad
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SurfaceDC.cls
115 lines (102 loc) · 2.64 KB
/
SurfaceDC.cls
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
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 = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Attribute VB_Ext_KEY = "SavedWithClassBuilder6" ,"Yes"
Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
Option Explicit
' cMemDC - flicker free drawing
Private m_hDC As Long
Private m_hBmp As Long
Private m_hBmpOld As Long
Private m_lWidth As Long
Private m_lHeight As Long
Public Property Get Width() As Long
Width = m_lWidth
End Property
Public Property Let Width(ByVal Value As Long)
Dim lJunk As Long
If (Value > m_lWidth) Then
m_lWidth = Value
pCreate m_lWidth, m_lHeight
SetBkMode m_hDC, 1
End If
End Property
Public Property Get Height() As Long
Height = m_lHeight
End Property
Public Property Let Height(ByVal Value As Long)
Dim lJunk As Long
If (Value > m_lHeight) Then
m_lHeight = Value
pCreate m_lWidth, m_lHeight
SetBkMode m_hDC, 1
End If
End Property
Public Property Get hdc() As Long
hdc = m_hDC
End Property
Public Function CreateFromBitmap(strFile As String)
'Creates a bitmap hdc
'Returns the bitmap hdc
pDestroy
Dim lngBitMapDC As Long
Dim vbPic As IPictureDisp
lngBitMapDC = CreateCompatibleDC(0)
Set vbPic = LoadPicture(strFile)
SelectObject lngBitMapDC, vbPic
m_lHeight = vbPic.Height / 26.45454545455
m_lWidth = vbPic.Width / 26.45454545455
m_hDC = lngBitMapDC
End Function
Private Sub pCreate(ByVal Width As Long, ByVal Height As Long)
Dim lhDCC As Long
Dim initData As DEVMODE
pDestroy
lhDCC = CreateDC("DISPLAY", "", "", initData)
If Not (lhDCC = 0) Then
m_hDC = CreateCompatibleDC(lhDCC)
If Not (m_hDC = 0) Then
m_hBmp = CreateCompatibleBitmap(lhDCC, Width, Height)
If Not (m_hBmp = 0) Then
m_hBmpOld = SelectObject(m_hDC, m_hBmp)
If Not (m_hBmpOld = 0) Then
m_lWidth = Width
m_lHeight = Height
DeleteDC lhDCC
Exit Sub
End If
End If
End If
DeleteDC lhDCC
pDestroy
End If
End Sub
Private Sub pDestroy()
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
m_lWidth = 0
m_lHeight = 0
End Sub
Private Sub Class_Terminate()
pDestroy
End Sub