-
Notifications
You must be signed in to change notification settings - Fork 12
/
Window.cls
239 lines (167 loc) · 5.95 KB
/
Window.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "Window"
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"
'--------------------------------------------------------------------------------
' Component : Window
' Project : ViDock
'
' Description: The Window object is an object orientated wrapper of
' a Window in Windows the operating system. myWindow.caption
' would be "Notepad" for example.
'
' Modified :
'--------------------------------------------------------------------------------
Option Explicit
'local variable(s) to hold property value(s)
Private mvarhWnd As Long 'local copy
Private mvarCaption As String 'local copy
Private mvarFlashing As Boolean 'local copy
Private mvarParent As Process 'local copy
Private mvarBitmap As GDIPBitmap
Public Function IsHung() As Boolean
Dim lResult As Long
Dim lReturn As Long
lReturn = SendMessageTimeout( _
mvarhWnd, WM_NULL, 0&, 0&, SMTO_ABORTIFHUNG Or SMTO_BLOCK, 1000, lResult)
If lReturn Then
IsHung = False
Exit Function
End If
IsHung = True
End Function
Public Property Get Image() As GDIPImage
Set Image = mvarBitmap.Image
End Property
Public Function IsMaximized() As Boolean
IsMaximized = IIf(IsZoomed(mvarhWnd) = APITRUE, True, False)
End Function
Public Function isMinimized() As Boolean
isMinimized = IIf(IsIconic(mvarhWnd) = APITRUE, True, False)
End Function
Public Function UpdateImage()
On Error GoTo Handler
If Me.IsHung Then
Exit Function
End If
Dim g As New GDIPGraphics
Dim bm As New GDIPBitmap
Dim bmTemp As New GDIPBitmap
Dim gTemp As New GDIPGraphics
Dim hdc As Long
Dim rc As Win.RECT
Dim hBitmap As Long
Dim newWidth As Long
Dim newHeight As Long
Dim aspect_width As Single
Dim aspect_height As Single
mvarBitmap.Dispose
GetWindowRect mvarhWnd, rc
aspect_width = RECTWIDTH(rc) / RECTHEIGHT(rc)
aspect_height = RECTHEIGHT(rc) / RECTWIDTH(rc)
newWidth = WINDOW_IMAGE_HEIGHT * aspect_width
newHeight = WINDOW_IMAGE_WIDTH * aspect_height
If newWidth > WINDOW_IMAGE_WIDTH Or WINDOW_IMAGE_WIDTH < 0 Then
newWidth = WINDOW_IMAGE_WIDTH
End If
If newHeight > WINDOW_IMAGE_HEIGHT Then
newHeight = WINDOW_IMAGE_HEIGHT
End If
bm.CreateFromSizeFormat RECTWIDTH(rc), RECTHEIGHT(rc), GDIPlusWrapper.Format32bppArgb
g.FromImage bm.Image
hdc = g.GetHDC
RepaintWindow mvarhWnd
If PrintWindow(mvarhWnd, hdc, 0) = 0 Then
Debug.Print "UpdateImage failed"
End If
g.ReleaseHDC hdc
g.flush FlushIntentionFlush
hBitmap = bm.hBitmap(vbBlack)
bmTemp.CreateFromHBITMAP hBitmap, 0
DeleteObject hBitmap
mvarBitmap.CreateFromSizeFormat newWidth, newHeight, GDIPlusWrapper.Format32bppArgb
gTemp.FromImage mvarBitmap.Image
gTemp.SmoothingMode = SmoothingModeHighQuality
gTemp.InterpolationMode = InterpolationModeHighQualityBicubic
gTemp.PixelOffsetMode = PixelOffsetModeHighQuality
gTemp.DrawImage bmTemp.Image, 0, 0, CSng(newWidth), CSng(newHeight)
Handler:
End Function
Public Property Get WindowState() As FormWindowStateConstants
If isMinimized Then
WindowState = vbMinimized
ElseIf IsMaximized Then
WindowState = vbMaximized
Else
WindowState = vbNormal
End If
End Property
Public Property Set Parent(ByVal vData As Process)
'used when assigning an Object to the property, on the left side of a Set statement.
'Syntax: Set x.Parent = Form1
Set mvarParent = vData
End Property
Public Property Get Parent() As Process
'used when retrieving value of a property, on the right side of an assignment.
'Syntax: Debug.Print X.Parent
Set Parent = mvarParent
End Property
Public Property Let Flashing(ByVal vData As Boolean)
'used when assigning a value to the property, on the left side of an assignment.
'Syntax: X.Flashing = 5
mvarFlashing = vData
End Property
Public Property Get Flashing() As Boolean
'used when retrieving value of a property, on the right side of an assignment.
'Syntax: Debug.Print X.Flashing
Flashing = mvarFlashing
End Property
Public Property Let Caption(ByVal vData As String)
'used when assigning a value to the property, on the left side of an assignment.
'Syntax: X.Caption = 5
mvarCaption = vData
End Property
Public Property Get Caption() As String
'used when retrieving value of a property, on the right side of an assignment.
'Syntax: Debug.Print X.Caption
Caption = mvarCaption
End Property
Public Property Let hWnd(ByVal vData As Long)
'used when assigning a value to the property, on the left side of an assignment.
'Syntax: X.hWnd = 5
If vData = 0 Then
LogError 299, "hWnd->Invalid hWnd", "Class::Window"
Exit Property
End If
mvarhWnd = vData
UpdateWindowText
End Property
Public Function UpdateWindowText()
If mvarhWnd = 0 Then Exit Function
If Me.IsHung Then Exit Function
Dim lReturn As Long
mvarCaption = Space$(256)
lReturn = GetWindowText(hWnd, mvarCaption, Len(mvarCaption))
If lReturn Then
mvarCaption = Left$(mvarCaption, lReturn)
End If
End Function
Public Property Get hWnd() As Long
'used when retrieving value of a property, on the right side of an assignment.
'Syntax: Debug.Print X.hWnd
hWnd = mvarhWnd
End Property
Private Sub Class_Initialize()
Set mvarBitmap = New GDIPBitmap
End Sub