用API函數(shù)GetWindowText。
10年積累的成都做網(wǎng)站、成都網(wǎng)站設(shè)計(jì)經(jīng)驗(yàn),可以快速應(yīng)對(duì)客戶對(duì)網(wǎng)站的新想法和需求。提供各種問題對(duì)應(yīng)的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認(rèn)識(shí)你,你也不認(rèn)識(shí)我。但先網(wǎng)站制作后付款的網(wǎng)站建設(shè)流程,更有青山湖免費(fèi)網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。
GetWindowText
VB聲明
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
說明
取得一個(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)行窮舉。
如果你裝了金山詞霸,可以這樣
從“引用”中添加XdictGrb.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
Private?Sub?TextBox1_Click(sender?As?Object,?e?As?EventArgs)?Handles?TextBox1.Click
TextBox1.SelectAll()
TextBox1.ForeColor?=?Color.Blue
End?Sub
如果不想每次都這樣的話,就加一個(gè)if判斷TextBox1.ForeColor 是否是Color.Blue就可以了
添加引用:Microsoft.mshtml,然后代碼如下即可:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'獲取用戶選中的文字
Dim htmlDocument As mshtml.IHTMLDocument2 'IHTMLDocument2
htmlDocument = WebBrowser1.Document.DomDocument
Dim currentSelection As mshtml.IHTMLSelectionObject
currentSelection = htmlDocument.selection
Dim range As mshtml.IHTMLTxtRange
If Not (currentSelection Is Nothing) Then
range = currentSelection.createRange()
If Not (range Is Nothing) Then
MsgBox(range.text)
'tbKeyWord.Text = range.text;
End If
End If
End Sub
網(wǎng)站欄目:vb.net鼠標(biāo)取詞,電腦鼠標(biāo)取詞翻譯
文章轉(zhuǎn)載:http://chinadenli.net/article30/hddjpo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供定制網(wǎng)站、面包屑導(dǎo)航、自適應(yīng)網(wǎng)站、品牌網(wǎng)站設(shè)計(jì)、手機(jī)網(wǎng)站建設(shè)、ChatGPT
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)