如果你裝了金山詞霸,可以這樣
讓客戶(hù)滿意是我們工作的目標(biāo),不斷超越客戶(hù)的期望值來(lái)自于我們對(duì)這個(gè)行業(yè)的熱愛(ài)。我們立志把好的技術(shù)通過(guò)有效、簡(jiǎn)單的方式提供給客戶(hù),將通過(guò)不懈努力成為客戶(hù)在信息化領(lǐng)域值得信任、有價(jià)值的長(zhǎng)期合作伙伴,公司提供的服務(wù)項(xiàng)目有:主機(jī)域名、虛擬空間、營(yíng)銷(xiāo)軟件、網(wǎng)站建設(shè)、任縣網(wǎng)站維護(hù)、網(wǎng)站推廣。
從“引用”中添加X(jué)dictGrb.dll
Option Explicit
Implements IXDictGrabSink
Private gp As GrabProxyPrivate Sub Form_Load()
Set gp = New GrabProxy
With gp
.GrabEnabled = True '是否有效
.GrabInterval = 30 '指定抓取時(shí)間間隔
.GrabMode = XDictGrabMouse '模式(鼠標(biāo)是否加按鍵)
.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 = "當(dāng)前坐標(biāo):" "(" lCursorX "," lCursorY ")"
Label2.Caption = "當(dāng)前語(yǔ)句:" SentenceString
Label3.Caption = "當(dāng)前字符:" Mid(SentenceString, lLoc + 1, 1000)
End Function
在有些軟件里當(dāng)鼠標(biāo)移到某單詞上,其注釋就會(huì)顯示單詞的中文解釋.這樣的軟件是如何制作的呢?下面我就介紹以下獲取鼠標(biāo)所在單詞的方法,至于中文結(jié)實(shí)要關(guān)系到數(shù)據(jù)庫(kù)及字庫(kù)問(wèn)題在此我不做解釋.
首先建立新工程,在FORM上添加一個(gè)TEXT文本框.
聲明SendMessage函數(shù).
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注釋?zhuān)涸贏PI瀏覽器里無(wú)此值請(qǐng)自己加上.
自定義過(guò)程:
Private Sub Text1_MouseDown(Button As Intege,Shift As Integer,x As Single, y As Single)
注釋?zhuān)韩@取鼠標(biāo)所點(diǎn)的是第幾行第幾個(gè)字符
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 注釋?zhuān)旱趲仔?/p>
CharPos=Lc MOD 65536 注釋?zhuān)旱趲讉€(gè)字符
End Sub
注釋?zhuān)航酉聛?lái)才是真正的讀取函數(shù)
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)注釋?zhuān)恨D(zhuǎn)換成Byte數(shù)組
pos1=0:pos2=UBound(bArr)
注釋?zhuān)合蚯八阉鞣指穹奈恢?/p>
For i=pos-1 To 0 Step -1
If IsDelimiter(bArr(i)) Then
pos1=i+1
Exit For
End If
Next
注釋?zhuān)合蚝笏褜し指舴址奈恢?/p>
For i=pos To UBound(bArr)
If IsDelimiter(bArr(i)) Then
pos2=i-1
Exit For
End If
Next
注釋?zhuān)航厝os1-pos2之間的字符,以構(gòu)成一個(gè)單詞
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
注釋?zhuān)篒sDelimiter函數(shù)
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
用API函數(shù)GetWindowText。
GetWindowText
VB聲明
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
說(shuō)明
取得一個(gè)窗體的標(biāo)題文字,或者一個(gè)控件的內(nèi)容
返回值:Long,復(fù)制到lpString的字串長(zhǎng)度;不包括空中止字符。會(huì)設(shè)置GetLastError
參數(shù)表
hwnd: Long,欲獲取文字的那個(gè)窗口的句柄
lpString: String,預(yù)定義的一個(gè)緩沖區(qū),至少有cch+1個(gè)字符大小;隨同窗口文字載入
cch: Long,lpString緩沖區(qū)的長(zhǎng)度
注解
不能用它從另一個(gè)應(yīng)用程序的編輯控件中獲取文字
我要補(bǔ)充以下,如果不知道句柄,那么可以用For計(jì)數(shù)循環(huán)進(jìn)行窮舉。
1.隨機(jī)產(chǎn)生英文字母
Randomize() '功 能:初始化隨機(jī)數(shù)發(fā)生器
Me.txt1.Text = Chr(Asc("a") + Int(Rnd() * 26))
'Rnd 函數(shù)返回小于 1 但大于或等于 0 的值。
'0 = Rnd() * 26 26 是含小數(shù)位的數(shù)
'Int(Rnd() * 26) 轉(zhuǎn)換為整型,就是0~25的隨機(jī)數(shù)
'Asc("a") 得到a的ASCii數(shù)值,是整數(shù)97(A是65)
'a~z的ASCii為97~122 ,即為a~z之間的字母為97加(0~25)
'Asc("a") + Int(Rnd() * 26)為97到122的隨機(jī)數(shù)
'Chr()又可以起到轉(zhuǎn)換成字符的功能,Chr(97)表示a (a轉(zhuǎn)換成數(shù)值又是Asc("a")=97)
'Chr(Asc("a") + Int(Rnd() * 26))就是a~z的隨機(jī)數(shù)了
Randomize() '再次初始化隨機(jī)數(shù)發(fā)生器
Me.txt2.Text = Chr(Asc("A") + Int(Rnd() * 26)) '這里是A~Z的隨機(jī)數(shù)
'也可以換這種寫(xiě)法
Randomize()
Me.txt1.Text = Chr(Int((26 * Rnd()) + 97)) '這里是a~z的隨機(jī)數(shù)
'這是在你知道ASCII碼的情況之下(a~z為97~122,A~Z為65~90)
'Rnd()為0~0.9999999.....的隨機(jī)數(shù)
' 26 * Rnd()為0~25.9999...的隨機(jī)數(shù)
'Int((26 * Rnd())為0~25的隨機(jī)數(shù)
'Int((26 * Rnd()) + 97)為97~122的隨機(jī)數(shù)
'Chr(Int((26 * Rnd()) + 97))就是a~z的隨機(jī)數(shù)了
Randomize()
Me.txt2.Text = Chr(Int((26 * Rnd()) + 65)) '這里是A~Z的隨機(jī)數(shù)
'至于同時(shí)在一處隨機(jī)大寫(xiě)或小寫(xiě),ASCII碼的數(shù)字又不挨在一起(65-90,97-122),比較麻煩。想寫(xiě)的話,你可以自己想一下怎么辦
2.數(shù)字怎樣轉(zhuǎn)換成ASCII碼所對(duì)應(yīng)的字母
Chr()函數(shù)將數(shù)字轉(zhuǎn)換成ASCII對(duì)應(yīng)的字母,Asc()函數(shù)將字母根據(jù)ASCII表轉(zhuǎn)換成數(shù)字
Chr(97)表示a (a轉(zhuǎn)換成數(shù)值又是Asc("a")=97)
3.加到數(shù)組,你可以放在一個(gè)for循環(huán)里
比如
Dim arylst1 As New ArrayList
Dim arr1() As String '數(shù)組
Dim str1 As String
For i As Integer = 1 To 15 '比如我想要15個(gè)隨機(jī)字母
Randomize()
str1 = Chr(Int((26 * Rnd()) + 65)) '這里是A~Z的隨機(jī)數(shù)
arylst1.Add(str1)
Next
ReDim arr1(arylst1.Count - 1) '這里是為了比較動(dòng)態(tài),可以只改變 i 的范圍來(lái)決定要多少個(gè)隨機(jī)字母
'當(dāng)然也可以寫(xiě)死,在前面直接定義為 arr1(14),下次要改的時(shí)候就要改定義的地方和i的范圍,改兩個(gè)地方
arylst1.CopyTo(arr1)
'就把數(shù)值拷貝到數(shù)組里面了