用API函數GetWindowText。
10年積累的成都做網站、成都網站設計經驗,可以快速應對客戶對網站的新想法和需求。提供各種問題對應的解決方案。讓選擇我們的客戶得到更好、更有力的網絡服務。我雖然不認識你,你也不認識我。但先網站制作后付款的網站建設流程,更有青山湖免費網站建設讓你可以放心的選擇與我們合作。
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計數循環進行窮舉。
如果你裝了金山詞霸,可以這樣
從“引用”中添加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, 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
如果不想每次都這樣的話,就加一個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
網站欄目:vb.net鼠標取詞,電腦鼠標取詞翻譯
文章轉載:http://m.kartarina.com/article30/hddjpo.html
成都網站建設公司_創新互聯,為您提供定制網站、面包屑導航、自適應網站、品牌網站設計、手機網站建設、ChatGPT
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯