vb 这个api函数怎么写!![取文本文档的窗口标题]
GetWindowTextVB声明DeclareFunctionGetWindowTextLib"user32"Alias"GetWindowTextA"(ByValhw...
GetWindowTextVB声明Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long说明取得一个窗体的标题(caption)文字,或者一个控件的内容(在vb里使用:使用vb窗体或控件的caption或text属性)返回值Long,复制到lpString的字串长度;不包括空中止字符。会设置GetLastError参数表参数类型及说明hwndLong,欲获取文字的那个窗口的句柄lpStringString,预定义的一个缓冲区,至少有cch+1个字符大小;随同窗口文字载入cchLong,lpString缓冲区的长度注解不能用它从另一个应用程序的编辑控件中获取文字Top取文本文档的标题!到text!
展开
展开全部
换个别的API
Private Declare Function WindowFromPoint Lib "user32" Alias "WindowFromPoint" (ByVal xPoint As Integer, ByVal yPoint As Integer) As IntPtr
Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As IntPtr) As Integer
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As IntPtr, ByVal lpString As String, ByVal cch As Integer) As Integer
Private Structure TitleEXD
<VBFixedString(255)> Public Text As String
End Structure
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim x As Integer = MousePosition.X, y As Integer = MousePosition.Y, res As String
Label1.Text = "鼠标当前坐标:" & x & "," & y
Dim hwnd As IntPtr = WindowFromPoint(x, y)
Label2.Text = "句柄:" & hwnd.ToString()
Dim Tlong As Integer = GetWindowTextLength(hwnd) Mod 65536 + 1
Dim TitleE As TitleEXD
TitleE.Text = Space(255)
Dim dlld As Integer = GetWindowText(Me.Handle, TitleE.Text, Tlong) Mod 65536
Label3.Text = "窗口标题:" & TitleE.Text
If dlld = 0 Then
res = "失败"
Else
res = "成功"
End If
Label4.Text = "获取标题" & res
End Sub
Private Declare Function WindowFromPoint Lib "user32" Alias "WindowFromPoint" (ByVal xPoint As Integer, ByVal yPoint As Integer) As IntPtr
Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As IntPtr) As Integer
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As IntPtr, ByVal lpString As String, ByVal cch As Integer) As Integer
Private Structure TitleEXD
<VBFixedString(255)> Public Text As String
End Structure
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim x As Integer = MousePosition.X, y As Integer = MousePosition.Y, res As String
Label1.Text = "鼠标当前坐标:" & x & "," & y
Dim hwnd As IntPtr = WindowFromPoint(x, y)
Label2.Text = "句柄:" & hwnd.ToString()
Dim Tlong As Integer = GetWindowTextLength(hwnd) Mod 65536 + 1
Dim TitleE As TitleEXD
TitleE.Text = Space(255)
Dim dlld As Integer = GetWindowText(Me.Handle, TitleE.Text, Tlong) Mod 65536
Label3.Text = "窗口标题:" & TitleE.Text
If dlld = 0 Then
res = "失败"
Else
res = "成功"
End If
Label4.Text = "获取标题" & res
End Sub
2011-08-16
展开全部
先声明用到的api函数:
用findwindow函数,以notepad类来查找窗口句柄 这里用tmphwnd表示
其次要声明字符串变量lpstring如
dim tmpstr as string*20
函数调用时
getwindowtext tmphwnd,tmpstr,20+1
print left(tmpstr,len(tmphwnd))
如果不错,打印的应该就是文本文档标题了
用findwindow函数,以notepad类来查找窗口句柄 这里用tmphwnd表示
其次要声明字符串变量lpstring如
dim tmpstr as string*20
函数调用时
getwindowtext tmphwnd,tmpstr,20+1
print left(tmpstr,len(tmphwnd))
如果不错,打印的应该就是文本文档标题了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询