Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As LongPublic Declare Function GetForegroundWindow Lib "user32" Alias "GetForegroundWindow" () As Long注:GetForegroundWindow取得当前焦点所在的窗口
FindWindow VB声明 Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long 说明 寻找窗口列表中第一个符合指定条件的顶级窗口(在vb里使用:FindWindow最常见的一个用途是获得ThunderRTMain类的隐藏窗口的句柄;该类是所有运行中vb执行程序的一部分。获得句柄后,可用api函数GetWindowText取得这个窗口的名称;该名也是应用程序的标题) 返回值 Long,找到窗口的句柄。如未找到相符窗口,则返回零。会设置GetLastError 参数表 参数 类型及说明 lpClassName String,指向包含了窗口类名的空中止(C语言)字串的指针;或设为零,表示接收任何类 lpWindowName String,指向包含了窗口文本(或标签)的空中止(C语言)字串的指针;或设为零,表示接收任何窗口标题 注解 很少要求同时按类与窗口名搜索。为向自己不准备参数传递一个零,最简便的办法是传递vbNullString常数
示例 Dim hw&, cnt& Dim rttitle As String * 256 hw& = FindWindow("ThunderRT5Main", vbNullString) ' ThunderRTMain under VB4 cnt = GetWindowText(hw&, rttitle, 255) MsgBox Left$(rttitle, cnt), 0, "RTMain title" GetWindowText VB声明 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 参数表 参数 类型及说明 hwnd Long,欲获取文字的那个窗口的句柄 lpString String,预定义的一个缓冲区,至少有cch+1个字符大小;随同窗口文字载入 cch Long,lpString缓冲区的长度 注解 不能用它从另一个应用程序的编辑控件中获取文字
GetForegroundWindow VB声明 Declare Function GetForegroundWindow Lib "user32" Alias "GetForegroundWindow" () As Long 说明 获得前台窗口的句柄。这里的“前台窗口”是指前台应用程序的活动窗口 返回值 Long,前台窗口的句柄 注解 windows nt支持多个桌面,它们相互间是独立的。每个桌面都有自己的前台窗口
getwindowtext function obtain the window title
GetWindowText(handle, str,len(str))
GetWindowText(handle, str,len(str))
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As LongPublic Declare Function GetForegroundWindow Lib "user32" Alias "GetForegroundWindow" () As Long注:GetForegroundWindow取得当前焦点所在的窗口
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
说明
寻找窗口列表中第一个符合指定条件的顶级窗口(在vb里使用:FindWindow最常见的一个用途是获得ThunderRTMain类的隐藏窗口的句柄;该类是所有运行中vb执行程序的一部分。获得句柄后,可用api函数GetWindowText取得这个窗口的名称;该名也是应用程序的标题)
返回值
Long,找到窗口的句柄。如未找到相符窗口,则返回零。会设置GetLastError
参数表
参数 类型及说明
lpClassName String,指向包含了窗口类名的空中止(C语言)字串的指针;或设为零,表示接收任何类
lpWindowName String,指向包含了窗口文本(或标签)的空中止(C语言)字串的指针;或设为零,表示接收任何窗口标题
注解
很少要求同时按类与窗口名搜索。为向自己不准备参数传递一个零,最简便的办法是传递vbNullString常数
示例
Dim hw&, cnt&
Dim rttitle As String * 256
hw& = FindWindow("ThunderRT5Main", vbNullString) ' ThunderRTMain under VB4
cnt = GetWindowText(hw&, rttitle, 255)
MsgBox Left$(rttitle, cnt), 0, "RTMain title" GetWindowText VB声明
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
参数表
参数 类型及说明
hwnd Long,欲获取文字的那个窗口的句柄
lpString String,预定义的一个缓冲区,至少有cch+1个字符大小;随同窗口文字载入
cch Long,lpString缓冲区的长度
注解
不能用它从另一个应用程序的编辑控件中获取文字
Declare Function GetForegroundWindow Lib "user32" Alias "GetForegroundWindow" () As Long
说明
获得前台窗口的句柄。这里的“前台窗口”是指前台应用程序的活动窗口
返回值
Long,前台窗口的句柄
注解
windows nt支持多个桌面,它们相互间是独立的。每个桌面都有自己的前台窗口
用发送消息好像可以,但我记不清了。不行只有用hook了
GetWindowText(handle, str,len(str))
handle=GetForegroundWindow()
GetWindowText(handle, str,len(str))
GetWindowText