Private Declare Function sendMessage& Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any)
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) 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 GetActiveWindow Lib "user32" () As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As LongConst WM_SETTEXT = &HC
Const WM_KEYDOWN = &H100
Const WM_KEYUP = &H101
Const WM_CHAR = &H102
Const VK_A = &H41Dim cd As Boolean
Dim current As StringPrivate Sub Command1_Click()
Clipboard.Clear
Clipboard.SetText Text2
End SubPrivate Sub Command2_Click()
draw.Cls
buffer.Cls
End SubPrivate Sub Command3_Click()
Text2 = ""
End SubPrivate Sub Command4_Click()
Clipboard.Clear
Clipboard.SetText Text2
Text2 = ""
End Sub
Private Sub Form_Load()
cd = False
buffer.DrawStyle = vbSolid
End Sub
Private Sub draw_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
cd = True
draw.ForeColor = vbBlack
draw.DrawWidth = 10
draw.PSet (X, Y)
End Sub
Private Sub draw_Mousemove(Button As Integer, Shift As Integer, X As Single, Y As Single)
draw.ForeColor = vbBlack
draw.DrawWidth = 10
If cd Then draw.PSet (X, Y)
End SubPrivate Sub draw_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
draw.ForeColor = vbBlack
cd = False
showbuffer
End SubPrivate Sub showbuffer()
Dim bool1stScan As Boolean
Dim ax As Integer
Dim ay As Integer
Dim bx As Integer
Dim by As Integerbool1stScan = True
current = ""
buffer.Cls
For i = 1 To draw.Width + 100 Step 100
For j = 1 To draw.Height + 100 Step 100
If draw.Point(i, j) = vbBlack Then
buffer.PSet (i, j)
If Not bool1stScan Then
If i <= ax Then
ax = i
End If
If i >= bx Then
bx = i
End If
If j <= ay Then
ay = j
End If
If j >= by Then
by = j
End If
Else
bool1stScan = False
ax = i
bx = i
ay = j
by = j
End If
End If
Next j, iIf bx - ax <> 0 And by - ay <> 0 Then a = 180
b = 180
Me.buffer.Cls
For i = ax To bx - (bx - ax) / 20 Step (bx - ax) / 20
For j = ay To by - (by - ay) / 20 Step (by - ay) / 20
If draw.Point(i, j) = vbBlack Then
buffer.PSet (a, b)
buffer.Line (a - 50, b - 50)-(a + 50, b - 50)
buffer.Line (a + 50, b - 50)-(a + 50, b + 50)
buffer.Line (a + 50, b + 50)-(a - 50, b + 50)
buffer.Line (a - 50, b + 50)-(a - 50, b - 50)
current = current & draw.Point(i, j)
Else
current = current & 1
End If
b = b + (Me.buffer.Height - 200) / 20
Next j
b = 180
a = a + (Me.buffer.Width - 200) / 20
Next i
End If
End SubPrivate Sub learn_Click()
Dim s As String
Open "d:\data.rec" For Append As #1
s = Text1.Text + current
Print #1, s
Close #1
learn.Enabled = False
End SubPrivate Sub recog_Click()
Dim i, max, maxtch As Integer
Dim template, ans, name, s As String
template = ""
max = 0
Open "d:\data.rec" For Input As #1
While Not EOF(1)
Input #1, s
match = 0
template = Right(s, Len(s) - 1)
name = Left(s, 1)
i = 1
While i <= Len(current) And Len(current) - i + match >= max
If Mid(current, i, 1) = Mid(template, i, 1) Then match = match + 1
i = i + 1
Wend
If match > max Then
max = match
ans = name
End If
Wend
Close #1
Text2 = Text2 + ans
Dim h1 As Long
Dim h2 As Long
h1 = FindWindow(vbNullString, "1 - 记事本")
h2 = FindWindowEx(h1, 0&, "Edit", vbNullString)
sendMessage h2, WM_SETTEXT, 0, ByVal CStr(ans)
End SubPrivate Sub Text1_Change()
If Len(Text1.Text) >= 1 Then
learn.Enabled = True
Else
learn.Enabled = False
End If
End Sub
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) 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 GetActiveWindow Lib "user32" () As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As LongConst WM_SETTEXT = &HC
Const WM_KEYDOWN = &H100
Const WM_KEYUP = &H101
Const WM_CHAR = &H102
Const VK_A = &H41Dim cd As Boolean
Dim current As StringPrivate Sub Command1_Click()
Clipboard.Clear
Clipboard.SetText Text2
End SubPrivate Sub Command2_Click()
draw.Cls
buffer.Cls
End SubPrivate Sub Command3_Click()
Text2 = ""
End SubPrivate Sub Command4_Click()
Clipboard.Clear
Clipboard.SetText Text2
Text2 = ""
End Sub
Private Sub Form_Load()
cd = False
buffer.DrawStyle = vbSolid
End Sub
Private Sub draw_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
cd = True
draw.ForeColor = vbBlack
draw.DrawWidth = 10
draw.PSet (X, Y)
End Sub
Private Sub draw_Mousemove(Button As Integer, Shift As Integer, X As Single, Y As Single)
draw.ForeColor = vbBlack
draw.DrawWidth = 10
If cd Then draw.PSet (X, Y)
End SubPrivate Sub draw_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
draw.ForeColor = vbBlack
cd = False
showbuffer
End SubPrivate Sub showbuffer()
Dim bool1stScan As Boolean
Dim ax As Integer
Dim ay As Integer
Dim bx As Integer
Dim by As Integerbool1stScan = True
current = ""
buffer.Cls
For i = 1 To draw.Width + 100 Step 100
For j = 1 To draw.Height + 100 Step 100
If draw.Point(i, j) = vbBlack Then
buffer.PSet (i, j)
If Not bool1stScan Then
If i <= ax Then
ax = i
End If
If i >= bx Then
bx = i
End If
If j <= ay Then
ay = j
End If
If j >= by Then
by = j
End If
Else
bool1stScan = False
ax = i
bx = i
ay = j
by = j
End If
End If
Next j, iIf bx - ax <> 0 And by - ay <> 0 Then a = 180
b = 180
Me.buffer.Cls
For i = ax To bx - (bx - ax) / 20 Step (bx - ax) / 20
For j = ay To by - (by - ay) / 20 Step (by - ay) / 20
If draw.Point(i, j) = vbBlack Then
buffer.PSet (a, b)
buffer.Line (a - 50, b - 50)-(a + 50, b - 50)
buffer.Line (a + 50, b - 50)-(a + 50, b + 50)
buffer.Line (a + 50, b + 50)-(a - 50, b + 50)
buffer.Line (a - 50, b + 50)-(a - 50, b - 50)
current = current & draw.Point(i, j)
Else
current = current & 1
End If
b = b + (Me.buffer.Height - 200) / 20
Next j
b = 180
a = a + (Me.buffer.Width - 200) / 20
Next i
End If
End SubPrivate Sub learn_Click()
Dim s As String
Open "d:\data.rec" For Append As #1
s = Text1.Text + current
Print #1, s
Close #1
learn.Enabled = False
End SubPrivate Sub recog_Click()
Dim i, max, maxtch As Integer
Dim template, ans, name, s As String
template = ""
max = 0
Open "d:\data.rec" For Input As #1
While Not EOF(1)
Input #1, s
match = 0
template = Right(s, Len(s) - 1)
name = Left(s, 1)
i = 1
While i <= Len(current) And Len(current) - i + match >= max
If Mid(current, i, 1) = Mid(template, i, 1) Then match = match + 1
i = i + 1
Wend
If match > max Then
max = match
ans = name
End If
Wend
Close #1
Text2 = Text2 + ans
Dim h1 As Long
Dim h2 As Long
h1 = FindWindow(vbNullString, "1 - 记事本")
h2 = FindWindowEx(h1, 0&, "Edit", vbNullString)
sendMessage h2, WM_SETTEXT, 0, ByVal CStr(ans)
End SubPrivate Sub Text1_Change()
If Len(Text1.Text) >= 1 Then
learn.Enabled = True
Else
learn.Enabled = False
End If
End Sub
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货