forked from lee-soft/ViPad
-
Notifications
You must be signed in to change notification settings - Fork 0
/
APIText.cls
117 lines (82 loc) · 3.02 KB
/
APIText.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
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "APIText"
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
Private Declare Function SendMessageW Lib "user32" _
(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private m_hWnd As Long
Private m_hDC As Long
Private m_font As GDIFont
Implements IHookSink
Public Event onClose()
Public Property Get hWnd() As Long
hWnd = m_hWnd
End Property
Public Property Let ParentHwnd(newParentHwnd As Long)
Initialize newParentHwnd
End Property
Public Property Let Text(newText As String)
Dim bString() As Byte
bString = newText
SendMessageW m_hWnd, WM_SETTEXT, 0&, StrPtr(bString)
End Property
Public Property Get Text() As String
Dim iLength As Long
Dim bString As String
iLength = SendMessageW(m_hWnd, WM_GETTEXTLENGTH, 0&, 0&)
bString = Space(iLength)
SendMessageW m_hWnd, WM_GETTEXT, iLength + 1, StrPtr(bString)
Text = bString
End Property
Public Property Let FontAPI(ByRef newFont As GDIFont)
Set m_font = newFont
SendMessage m_hWnd, WM_SETFONT, ByVal m_font.Handle, MAKELPARAM(0, False)
End Property
Private Sub Class_Terminate()
UnhookWindow m_hWnd
DestroyWindow m_hWnd
End Sub
Private Function IHookSink_WindowProc(hWnd As Long, msg As Long, wp As Long, lp As Long) As Long
On Error GoTo Handler
If msg = WM_CHAR Then
If wp = vbKeyReturn Then
RaiseEvent onClose
Exit Function
End If
End If
' Just allow default processing for everything else.
IHookSink_WindowProc = _
InvokeWindowProc(hWnd, msg, wp, lp)
Exit Function
Handler:
' Just allow default processing for everything else.
IHookSink_WindowProc = _
InvokeWindowProc(hWnd, msg, wp, lp)
End Function
Private Sub Initialize(ParentHwnd As Long)
m_hWnd = CreateWindowExW(0, StrPtr("EDIT"), StrPtr("ViPick_Edit"), _
WS_VISIBLE Or WS_CHILD Or WS_EX_TOOLWINDOW Or ES_AUTOHSCROLL Or ES_AUTOVSCROLL Or ES_CENTER, _
0, 0, 0, 0, ParentHwnd, 0, GetModuleHandle(0), 0)
Dim thisFont As New GDIFont
thisFont.Constructor "Tahoma", 30, APIFALSE
Me.FontAPI = thisFont
HookWindow m_hWnd, Me
End Sub
Sub Resize(ByVal newWidth As Long, ByVal newHeight As Long)
MoveWindow m_hWnd, 0, 0, newWidth, newHeight, True
End Sub
Private Sub Form_Terminate()
UnhookWindow m_hWnd
DestroyWindow m_hWnd
End Sub