vb.net屏幕取单词 vba常用单词

如何用VB获取屏幕信息在有些软件里当鼠标移到某单词上,其注释就会显示单词vb.net屏幕取单词的中文解释.这样的软件是如何制作的呢?下面我就介绍以下获取鼠标所在单词的方法,至于中文结实要关系到数据库及字库问题在此我不做解释.
【vb.net屏幕取单词 vba常用单词】首先建立新工程,在FORM上添加一个TEXT文本框.
声明SendMessage函数.
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Const EM_CHARFORMPOS=HD7注释vb.net屏幕取单词:在API浏览器里无此值请自己加上.
自定义过程:
Private Sub Text1_MouseDown(Button As Intege,Shift As Integer,x As Single, y As Single)
注释:获取鼠标所点的是第几行第几个字符
Dim pos As Long,Lc As Long
Dim Line As Integer,CharPos As Integer
x=x/Screen.TwipsPerPixelX
y=y/Screen.TwipsperPixelY
pos=x y*65536
Lc=SendMessage(Text1.hwnd,EM_CHARFROMPOS,0,ByVal pos)
Line=Lc65536 注释:第几行
CharPos=Lc MOD 65536 注释:第几个字符
End Sub
注释:接下来才是真正的读取函数
Function GetWord(txt As TextBox,pos As Integer) As String
Dim bArr()As Byte,pos1 As Integer,pos2 As Integer, i As Integer
bArr=StrConv(txt.Text,vbFromUnicode)注释:转换成Byte数组
pos1=0:pos2=UBound(bArr)
注释:向前搜索分格符的位置
For i=pos-1 To 0 Step -1
If IsDelimiter(bArr(i)) Then
pos1=i 1
Exit For
End If
Next
注释:向后搜寻分隔符字符的位置
For i=pos To UBound(bArr)
If IsDelimiter(bArr(i)) Then
pos2=i-1
Exit For
End If
Next
注释:截取pos1-pos2之间的字符,以构成一个单词
If pos2pos1 Then
ReDim bArr2(pos2-pos1) As Byte
For i=pos1 To Pos2
bArr2(i-pos1)=bArr(i)
Next
GetWord=StrConv(bArr2,vbUnicode)
Else
GetWord=""
End If
End Function
注释:IsDelimiter函数
Functon IsDelimiter(ByVal Char As Byte) As Boolean
Dim S As String
S=Chr(Char)
IsDelimiter=False
If S=" " Or S="," Or S="." Or S="?" Or S="vbCr Or S=vbLf Then
IsDelimiter=True
End If
End Function
VB 屏幕取词如果你装了金山词霸,可以这样
从“引用”中添加XdictGrb.dll
Option Explicit
Implements IXDictGrabSink
Private gp As GrabProxyPrivate Sub Form_Load()
Set gp = New GrabProxy
With gp
.GrabEnabled = True '是否有效
.GrabInterval = 30 '指定抓取时间间隔
.GrabMode = XDictGrabMouse '模式(鼠标是否加按键)
.AdviseGrab Me '接口指向自身End WithEnd SubPrivate Sub Form_Unload(Cancel As Integer)
Set gp = Nothing
End Sub
Private Function IXDictGrabSink_QueryWord(ByVal WordString As String, ByVal lCursorX As Long, ByVal lCursorY As Long, ByVal SentenceString As String, lLoc As Long, lStart As Long) As Long
Label1.Caption = "当前坐标:""("lCursorX","lCursorY")"
Label2.Caption = "当前语句:"SentenceString
Label3.Caption = "当前字符:"Mid(SentenceString, lLoc1, 1000)
End Function
vb如何实现屏幕取词用API函数GetWindowText 。
GetWindowText
VB声明
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
说明
取得一个窗体的标题文字 , 或者一个控件的内容
返回值:Long,复制到lpString的字串长度;不包括空中止字符 。会设置GetLastError
参数表
hwnd: Long,欲获取文字的那个窗口的句柄
lpString: String,预定义的一个缓冲区 , 至少有cch 1个字符大?。凰嫱翱谖淖衷厝?
cch: Long,lpString缓冲区的长度
注解
不能用它从另一个应用程序的编辑控件中获取文字
我要补充以下,如果不知道句柄,那么可以用For计数循环进行穷举 。
关于vb.net屏幕取单词和vba常用单词的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站 。

    推荐阅读