forked from lee-soft/ViStart
-
Notifications
You must be signed in to change notification settings - Fork 0
/
VistaSearchBox.cls
263 lines (192 loc) · 6.96 KB
/
VistaSearchBox.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
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "VistaSearchBox"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
Private Declare Function CreateWindowExW Lib "user32.dll" (ByVal dwExStyle As Long, ByVal lpClassName As Long, ByVal lpWindowName As Long, ByVal dwStyle As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hWndParent As Long, ByVal hMenu As Long, ByVal hInstance As Long, ByRef lpParam As Any) As Long
'Dont remove this, it screws up unicode shit
Private Declare Function CallWindowProc Lib "user32" _
Alias "CallWindowProcA" _
(ByVal lpPrevWndFunc As Long, _
ByVal hWnd As Long, _
ByVal msg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long
Implements IHookSink
Public Event onFocus()
Public Event onLostFocus()
Public Event onKeyDown(ByRef KeyCode As Long)
Public Event onKeyUp(ByRef KeyCode As Long)
Public Event onChange()
Public Event onMouseWheel(ByVal wParam As Long)
Private m_hEdit As Long
Private m_hDC As Long
Private m_font As GDIFont
Private m_defWindowProc As Long
Private m_hasFocus As Boolean
Private WithEvents m_container As frmZOrderKeeper
Attribute m_container.VB_VarHelpID = -1
Private m_BackColour As Long
Private m_ForeColour As Long
Private m_FocusColour As Long
'Windows XP Box-Fix
Private m_WindowWidth As Long
Private m_WindowHeight As Long
Private m_backgroundBrush As GDIBrush
Public Property Let FocusColour(newFocusColour As Long)
m_FocusColour = newFocusColour
End Property
Public Property Let ForeColour(newForeColour As Long)
m_ForeColour = newForeColour
If m_hEdit <> 0 Then SetTextColor m_hEdit, m_ForeColour
End Property
Public Property Let BackColour(newBackColour As Long)
m_BackColour = newBackColour
If m_hEdit <> 0 Then SetBkColor m_hEdit, m_BackColour
If Not m_backgroundBrush Is Nothing Then m_backgroundBrush.Colour = newBackColour
End Property
Public Function SetKeyboardFocus()
win.SetFocus m_hEdit
End Function
Public Property Get Font() As GDIFont
Set Font = m_font
End Property
Public Property Let Font(ByRef newFont As GDIFont)
If newFont Is Nothing Then Exit Property
Set m_font = newFont
SendMessageW m_hEdit, WM_SETFONT, ByVal m_font.Handle, ByVal MAKELPARAM(False, 0)
End Property
Public Property Let Text(newText As String)
Dim bString() As Byte
bString = newText
SendMessageW m_hEdit, WM_SETTEXT, 0&, StrPtr(bString)
End Property
Public Property Get Text() As String
Dim iLength As Long
Dim bString As String
iLength = SendMessageW(m_hEdit, WM_GETTEXTLENGTH, 0&, 0&)
bString = Space$(iLength)
SendMessageW m_hEdit, WM_GETTEXT, iLength + 1, StrPtr(bString)
Text = bString
End Property
Public Property Get HasFocus() As Boolean
HasFocus = m_hasFocus
End Property
Public Property Get hWnd() As Long
hWnd = m_container.hWnd
End Property
Public Property Get real_hWnd() As Long
real_hWnd = m_hEdit
End Property
Private Sub Class_Initialize()
'MsgBox "VISTASEARCHBOX"
Set m_container = New frmZOrderKeeper
m_container.SubclassWindow
m_hEdit = CreateWindowExW(0, StrPtr("EDIT"), StrPtr("ViStart_Edit"), _
WS_VISIBLE Or WS_CHILD Or WS_EX_TOOLWINDOW Or ES_AUTOHSCROLL Or ES_AUTOVSCROLL Or ES_MULTILINE, _
0, 0, 0, 0, m_container.hWnd, 0, GetModuleHandle(0), 0)
m_hDC = GetWindowDC(m_hEdit)
SetWindowLong m_container.hWnd, GWL_STYLE, WS_VISIBLE Or WS_EX_TOOLWINDOW
m_defWindowProc = HookWindow(m_hEdit, Me)
m_BackColour = vbWhite
m_ForeColour = vbBlack
m_FocusColour = RGB(109, 109, 109)
If g_WindowsXP Then
Set m_backgroundBrush = New GDIBrush
m_backgroundBrush.Colour = vbWhite
End If
End Sub
Private Sub Class_Terminate()
If Not m_container Is Nothing Then Unload m_container
If m_hEdit <> 0 Then
DestroyWindow m_hEdit
End If
End Sub
Private Sub WindowsXP_WhiteTextBoxFix()
Dim targetRect As RECT
targetRect.Left = m_WindowWidth - 3
targetRect.Right = m_WindowWidth
targetRect.Bottom = m_WindowHeight
FillRect m_hDC, targetRect, m_backgroundBrush.Value
'SetPixel m_Hdc, 1, 1, vbBlack
End Sub
Private Function IHookSink_WindowProc(hWnd As Long, msg As Long, wp As Long, lp As Long) As Long
On Error GoTo Handler
'form-specific handler
Select Case msg
Case WM_SETFOCUS
m_hasFocus = True
RaiseEvent onFocus
Case WM_KILLFOCUS
m_hasFocus = False
RaiseEvent onLostFocus
Case WM_KEYDOWN
RaiseEvent onKeyDown(wp)
Case WM_KEYUP
RaiseEvent onKeyUp(wp)
If wp = vbKeyReturn Then
Exit Function
End If
Case WM_CHAR
If wp = vbKeyReturn Then
Exit Function
End If
Case WM_SIZE
'GetWindowRect m_hWnd, m_WindowDimensions
m_WindowWidth = LOWORD(lp)
m_WindowHeight = HiWord(lp)
Case WM_PAINT
'this takes care of messages when the
'handle specified is not that of the form
IHookSink_WindowProc = CallWindowProc(m_defWindowProc, _
hWnd, _
msg, _
wp, _
lp)
If g_WindowsXP Then
WindowsXP_WhiteTextBoxFix
End If
Case WM_MOUSEWHEEL
RaiseEvent onMouseWheel(wp)
End Select
'Exit Function
Handler:
'this takes care of messages when the
'handle specified is not that of the form
IHookSink_WindowProc = CallWindowProc(m_defWindowProc, _
hWnd, _
msg, _
wp, _
lp)
End Function
Private Sub m_container_onChange(ByVal hWnd As Long)
If hWnd = m_hEdit Then
RaiseEvent onChange
End If
End Sub
Private Sub m_container_onColorEdit(ByVal hWnd As Long, ByVal hEditBox As Long)
If hWnd = m_hEdit Then
Dim hdc As Long: hdc = hEditBox
SetBkMode hdc, OPAQUE
SetBkColor hdc, m_BackColour
'SetTextColor hdc, RGB(109, 109, 109)
If Me.HasFocus Then
SetTextColor hdc, m_FocusColour
ElseIf Me.Text = GetPublicString("strStartSearch", "Start Search") Then
SetTextColor hdc, m_ForeColour
End If
End If
End Sub
Private Sub m_container_onResize()
On Error Resume Next
MoveWindow m_hEdit, 0, 0, m_container.ScaleWidth, m_container.ScaleHeight, True
End Sub