
VB.NET中怎样用API获得文本框中的选中文本
展开全部
Public Declare Auto Function GetWindowText Lib "user32" Alias "GetWindowText" (ByVal hwnd As Integer, ByVal lpString As String, ByVal cch As Integer) As Integer
Public Declare Auto Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLength" (ByVal hwnd As Integer) As Integer
Public Function GetText(ByVal hwnd As Integer) As String
Dim nLen As Integer
nLen = GetWindowTextLength(hwnd)
GetText = Space(nLen)
GetWindowText(hwnd, GetText, nLen)
End Function
VS2008测试通过, 函数GetText传入的就是对应文本框的句柄.
Public Declare Auto Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLength" (ByVal hwnd As Integer) As Integer
Public Function GetText(ByVal hwnd As Integer) As String
Dim nLen As Integer
nLen = GetWindowTextLength(hwnd)
GetText = Space(nLen)
GetWindowText(hwnd, GetText, nLen)
End Function
VS2008测试通过, 函数GetText传入的就是对应文本框的句柄.
更多追问追答
追问
不行啊,返回的值是文本框中的全部内容啊。但我只想要选中内容。
追答
你已经获取了全部内容, 再在VB.NET里处理只取得部分内容不就行了...
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询