用VB开发即指即译的翻译器
Option Explicit
Private Const EM_CHARFROMPOS = &HD7
Private Type POINTAPI
X As Long
Y As Long
End Type
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 Sub Form_Load()
Dim dbname As String
Data1.Visible = False
dbname = App.Path
If Right$(dbname, 1) <> "\" Then dbname = dbname & "\"
dbname = dbname & "词汇"
Data1.DatabaseName = dbname
RichTextBox1.Text = "how are you"
End Sub
Private Sub Richtextbox1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim postwip As POINTAPI
Dim pos As Integer
Dim first_pos As Integer
Dim last_pos As Integer
Dim ch As String
Dim txt1 As String
Dim textlength As Integer
Dim txt2 As String
Dim sql As String
' 把位置坐标转换为像素.
postwip.X = X \ Screen.TwipsPerPixelX
postwip.Y = Y \ Screen.TwipsPerPixelY
'获得字符的值
pos = SendMessage(RichTextBox1.hWnd, EM_CHARFROMPOS, 0&, postwip)
If pos > 0 Then
'查找单词的开始位置.
txt1 = RichTextBox1.Text
For first_pos = pos To 1 Step -1
ch = Mid$(RichTextBox1.Text, first_pos, 1)
' 非字母,退出循环
If Not ((ch >= "a" And ch <= "z") Or (ch >= "A" And ch <= "Z")) Then Exit For
Next first_pos
first_pos = first_pos + 1
'查找单词的结尾位置
textlength = Len(txt1)
For last_pos = pos To textlength
ch = Mid$(txt1, last_pos, 1)
' 非字母,退出循环
If Not ((ch >= "a" And ch <= "z") Or (ch >= "A" And ch <= "Z"))
Then Exit
For
Next last_pos
last_pos = last_pos - 1
'通过开始位置,结尾位置取单词
If first_pos <= last_pos Then
txt2 = Mid$(txt1, first_pos, last_pos - first_pos + 1)
End If
End If
sql = "select * from 词 where 英文='" & txt2 & "'"
Data1.RecordSource = sql
Data1.Refresh
'若数据集中存在匹配单词,则显示该单词的中文意思,否则显示空串
If Data1.Recordset.BOF And Data1.Recordset.EOF Then
Text1.Text = " "
Else
Text1.Text = Data1.Recordset("中文")
End If
End Sub
没有合适的资源?快使用搜索试试~ 我知道了~
VB.rar.rar_单词
共2个文件
txt:2个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 121 浏览量
2022-09-14
15:43:28
上传
评论
收藏 1KB RAR 举报
温馨提示
本软件实现以下功能:捕捉鼠标位置,并在鼠标位置范围内查找离它最近的英文单词,然后在单词库(词汇.mdb)中查找该词的中文意思,并将其中文意思显示出来。
资源推荐
资源详情
资源评论
收起资源包目录
VB.rar.rar (2个子文件)
用VB开发即指即译的翻译器.txt 2KB
www.pudn.com.txt 218B
共 2 条
- 1
资源评论
局外狗
- 粉丝: 66
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功