-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCFLATHEADER.CLS
282 lines (245 loc) · 10.6 KB
/
CFLATHEADER.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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
END
Attribute VB_Name = "cFlatHeader"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
' ====================================================================================
' File: cFlatHeader.cls
' Author: SP McMahon
' Date: 15 August 1999
'
' Attach to the parent of any control containing a COMCTL32.DLL header
' control, and this routine will ensure the header paints in a flat style,
' like the header in DevStudio 6.
'
' Requires: SSUBTMR.DLL
'
' Date Who
' 15/09/99 SPM
' First release.
'
' ------------------------------------------------------------------------------------
' vbAccelerator
' >> Advanced, free VB Source Code.
'
' http://vbaccelerator.com/
' mailto:[email protected]
' ====================================================================================
Private Type POINTAPI
x As Long
y As Long
End Type
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Type HD_ITEM
mask As Long
cxy As Long
pszText As String
hbm As Long
cchTextMax As Long
fmt As Long
lParam As Long
' 4.70:
iImage As Long
iOrder As Long
End Type
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function IsWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function SendMessageByLong Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hdc As Long) As Long
Private Declare Function MoveToEx Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, lpPoint As POINTAPI) As Long
Private Declare Function LineTo Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long
Private Declare Function CreatePen Lib "gdi32" (ByVal nPenStyle As Long, ByVal nWidth As Long, ByVal crColor As Long) As Long
Private Declare Function Rectangle Lib "gdi32" (ByVal hdc As Long, ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function SetPixel Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, ByVal crColor As Long) As Long
Private Declare Function GetSysColor Lib "user32" (ByVal nIndex 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 OffsetRect Lib "user32" (lpRect As RECT, ByVal x As Long, ByVal y As Long) As Long
Private Declare Function ShowScrollBar Lib "user32" (ByVal hwnd As Long, ByVal wBar As Long, ByVal bShow As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Const GWL_EXSTYLE = (-20)
Private Const GWL_STYLE = (-16)
Private Const WS_EX_WINDOWEDGE = &H100
Private Const WS_EX_CLIENTEDGE = &H200
Private Const WS_EX_STATICEDGE = &H20000
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Const SWP_NOACTIVATE = &H10
Private Const SWP_NOZORDER = &H4
Private Const SWP_FRAMECHANGED = &H20 ' The frame changed: send WM_NCCALCSIZE
Private Const SWP_NOSIZE = &H1
Private Const SWP_NOMOVE = &H2
Private Const LVS_EX_FLATSB = &H100
Private Const LVM_FIRST = &H1000 '// ListView messages
Private Const LVM_GETEXTENDEDLISTVIEWSTYLE = (LVM_FIRST + 55)
Private Const LVM_SETEXTENDEDLISTVIEWSTYLE = (LVM_FIRST + 54) '// optional wParam == mask
Private Const SB_BOTH = 3
Private Const WC_HEADERA = "SysHeader32"
Private Const WC_HEADER = WC_HEADERA
Private Const HDM_FIRST = &H1200 '// Header messages
Private Const HDM_GETITEMCOUNT = (HDM_FIRST + 0)
Private Const HDM_ORDERTOINDEX = (HDM_FIRST + 15)
Private Const HDM_GETITEMA = (HDM_FIRST + 3)
Private Const HDM_GETITEM = HDM_GETITEMA
Private Const HDI_WIDTH = &H1
Private Const HDI_HEIGHT = HDI_WIDTH
Private Const HDI_TEXT = &H2
Private Const HDI_FORMAT = &H4
Private Const HDI_LPARAM = &H8
Private Const HDI_BITMAP = &H10
Private Const WM_PAINT = &HF
Private Const PS_SOLID = 0
' VB6 header in ListView is a new class:
Private Const WC_HEADER_VB6 = "msvb_lib_header"
Implements ISubclass
Private m_hWnd As Long
Public Property Get GridhWnd(ByVal hWndContainer As Long)
Dim lhWnd As Long
lhWnd = FindWindowEx(hWndContainer, 0, "ThunderRT5UserControl", "")
If Not lhWnd = 0 Then
' A little fix :)
ShowScrollBar lhWnd, SB_BOTH, 0
GridhWnd = lhWnd
End If
End Property
Public Sub Attach(ByVal hWndA As Long)
Dim sClassName As String
Dim iPos As Long
Dim hWndP As Long
Detach
sClassName = String$(256, 0)
GetClassName hWndA, sClassName, 255
iPos = InStr(sClassName, Chr$(0))
If Not iPos = 0 Then
sClassName = Left$(sClassName, iPos - 1)
End If
If (Not sClassName = WC_HEADER) And (Not sClassName = WC_HEADER_VB6) Then
hWndP = hWndA
hWndA = FindWindowEx(hWndP, 0, WC_HEADER, "")
If hWndA = 0 Then
hWndA = FindWindowEx(hWndP, 0, WC_HEADER_VB6, "")
End If
End If
If IsWindow(hWndA) Then
m_hWnd = hWndA
AttachMessage Me, m_hWnd, WM_PAINT
Else
Err.Raise 26020, App.EXEName & ".cFlatHeader", "Invalid Window Passed to cFlatHeader - no header control detected."
End If
End Sub
Public Sub Detach()
If Not m_hWnd = 0 Then
DetachMessage Me, m_hWnd, WM_PAINT
m_hWnd = 0
End If
End Sub
Private Sub Class_Terminate()
Detach
End Sub
Private Property Let ISubClass_MsgResponse(ByVal RHS As SSubTimer.EMsgResponse)
'
End Property
Private Property Get ISubClass_MsgResponse() As SSubTimer.EMsgResponse
ISubClass_MsgResponse = emrPreprocess
End Property
Private Function ISubClass_WindowProc(ByVal hwnd As Long, ByVal iMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If iMsg = WM_PAINT Then
Dim tR As RECT
Dim lC As Long
Dim lColIndex As Long
Dim i As Long
Dim tHI As HD_ITEM
Dim hdc As Long
Dim tJunk As POINTAPI
Dim lColor As Long
Dim hPen As Long, hPenOld As Long
Dim hPenFace As Long, hPenShadow As Long, hPenHighlight As Long
Dim lX As Long, lXStart As Long
GetWindowRect m_hWnd, tR
OffsetRect tR, -tR.Left, -tR.Top
hdc = GetDC(m_hWnd)
lColor = GetSysColor(vb3DHighlight And &H1F&)
hPenHighlight = CreatePen(PS_SOLID, 1, lColor)
lColor = GetSysColor(vbButtonFace And &H1F&)
hPenFace = CreatePen(PS_SOLID, 1, lColor)
lColor = GetSysColor(vbButtonShadow And &H1F&)
hPenShadow = CreatePen(PS_SOLID, 1, lColor)
lC = SendMessageByLong(m_hWnd, HDM_GETITEMCOUNT, 0, 0)
For i = 0 To lC - 1
tHI.mask = HDI_WIDTH
lColIndex = SendMessageByLong(m_hWnd, HDM_ORDERTOINDEX, i, 0)
If SendMessage(m_hWnd, HDM_GETITEM, lColIndex, tHI) <> 0 Then
lXStart = lX + 1
lX = lX + tHI.cxy
' Draw over existing shadow with btn face:
hPenOld = SelectObject(hdc, hPenFace)
MoveToEx hdc, lXStart, tR.Bottom - 2, tJunk
LineTo hdc, lX - 2, tR.Bottom - 2
LineTo hdc, lX - 2, tR.Top
SelectObject hdc, hPenOld
' Draw over existing black with shadow:
If GetPixel(hdc, lXStart, tR.Top) = lColor Then
' Item is depressed!
hPenOld = SelectObject(hdc, hPenHighlight)
Else
hPenOld = SelectObject(hdc, hPenShadow)
End If
MoveToEx hdc, lXStart - 1, tR.Bottom - 1, tJunk
LineTo hdc, lX - 1, tR.Bottom - 1
LineTo hdc, lX - 1, tR.Top - 1
SelectObject hdc, hPenOld
End If
Next i
If lX < tR.Right Then
' Draw over existing shadow with btn face:
hPenOld = SelectObject(hdc, hPenFace)
MoveToEx hdc, lX + 1, tR.Bottom - 2, tJunk
LineTo hdc, tR.Right, tR.Bottom - 2
SelectObject hdc, hPenOld
End If
' Clear up objects:
DeleteObject hPenFace
DeleteObject hPenShadow
DeleteObject hPenHighlight
ReleaseDC m_hWnd, hdc
End If
End Function
' Helper function for Control border
Public Property Let ThinBorder(ByVal hWndA As Long, ByVal bState As Boolean)
Dim lStyle As Long
' ListView should have Appearance set to flat and Border set to none for this to work:
lStyle = GetWindowLong(hWndA, GWL_EXSTYLE)
If bState Then
lStyle = lStyle And Not WS_EX_CLIENTEDGE Or WS_EX_STATICEDGE
Else
lStyle = lStyle Or WS_EX_CLIENTEDGE And Not WS_EX_STATICEDGE
End If
SetWindowLong hWndA, GWL_EXSTYLE, lStyle
SetWindowPos hWndA, 0, 0, 0, 0, 0, SWP_NOACTIVATE Or SWP_NOZORDER Or SWP_FRAMECHANGED Or SWP_NOSIZE Or SWP_NOMOVE
End Property
' Helper function for VB5 ListView = flat scroll bars:
Public Property Let LVFlatScrollBars(ByVal hWndA As Long, ByVal bValue As Boolean)
Dim lStyle As Long
lStyle = SendMessageByLong(hWndA, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0)
If bValue Then
lStyle = lStyle Or LVS_EX_FLATSB
Else
lStyle = lStyle And Not LVS_EX_FLATSB
End If
SendMessageByLong hWndA, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, lStyle
End Property