vb 知道窗口里的文字怎么获得控件句柄
比如我要获得ie7浏览器里第一个选项卡里的文字,要怎么获取...我只知道显示的是"百度知道--提问问题",我怎么知道这个标签的句柄...然后再在vb里根据这个句柄读出标签...
比如 我要获得ie7浏览器里第一个选项卡里的文字,要怎么获取...
我只知道显示的是"百度知道--提问问题",我怎么知道这个标签的句柄...
然后再在vb里根据这个句柄读出标签的文字...我要代码...回答的好马上给分... 展开
我只知道显示的是"百度知道--提问问题",我怎么知道这个标签的句柄...
然后再在vb里根据这个句柄读出标签的文字...我要代码...回答的好马上给分... 展开
7个回答
展开全部
要怎么知道那个标签的句柄你可以打开Windodws任务管理器看
下面举个例,当你打开百度首页(www.baidu.com)时
他的窗体句柄是:百度一下,你就知道 - Windows Internet Explorer
下面的代码
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Const STANDARD_RIGHTS_REQUIRED = &HF0000
Const SYNCHRONIZE = &H100000
Const SPECIFIC_RIGHTS_ALL = &HFFFF
Const STANDARD_RIGHTS_ALL = &H1F0000
Const PROCESS_ALL_ACCESS = STANDARD_RIGHTS_REQUIRED Or SYNCHRONIZE Or &HFFF
Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Private Sub Command1_Click()
Dim a As Long
Dim Pid As Long
Dim Jubing As Long
a = FindWindow(vbNullString, "百度一下,你就知道 - Windows Internet Explorer")
GetWindowThreadProcessId a, Pid
Jubing = OpenProcess(PROCESS_ALL_ACCESS, False, Pid)
TerminateProcess Jubing, 0
End Sub
'
下面举个例,当你打开百度首页(www.baidu.com)时
他的窗体句柄是:百度一下,你就知道 - Windows Internet Explorer
下面的代码
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Const STANDARD_RIGHTS_REQUIRED = &HF0000
Const SYNCHRONIZE = &H100000
Const SPECIFIC_RIGHTS_ALL = &HFFFF
Const STANDARD_RIGHTS_ALL = &H1F0000
Const PROCESS_ALL_ACCESS = STANDARD_RIGHTS_REQUIRED Or SYNCHRONIZE Or &HFFF
Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Private Sub Command1_Click()
Dim a As Long
Dim Pid As Long
Dim Jubing As Long
a = FindWindow(vbNullString, "百度一下,你就知道 - Windows Internet Explorer")
GetWindowThreadProcessId a, Pid
Jubing = OpenProcess(PROCESS_ALL_ACCESS, False, Pid)
TerminateProcess Jubing, 0
End Sub
'
展开全部
不好搞, 要IE7的内部支持了.
不如装回IE6, 直接找标题就行了.
不如装回IE6, 直接找标题就行了.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
可以从另一个方面来考虑。比如屏幕取词,有屏幕取词控件。也比较方便。可以取整句,也可以取单个文字。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
用遍历控件的方法可能还办得到。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
下面一段代码, 你使用前把API函数阅览器打开, 看看有什么效果.
Dim hwnd As Long
Dim str1 As String, len1 As Long
'hwnd = FindWindowa("ThunderRT6FormDC", "Form1") '编译成EXE用这句,
hwnd = FindWindowa("ThunderFormDC", "Form1") '在调试的时候用这句.
str1 = Space(255) '定义接收字串.
GetWindowText hwnd, str1, 1024
Do While hwnd <> 0
hwnd = GetNextWindow(hwnd, 2) '只有2才表示找下一个窗口
len1 = GetWindowText(hwnd, str1, Len(str1))
If (InStr(1, str1, "API", 1) > 0) Then
Exit Do
End If
Loop
SetWindowText hwnd, "我把API阅读器的标题改变了"
hwnd = GetNextWindow(hwnd, 5) '5表示子窗口
Do While hwnd <> 0
hwnd = GetNextWindow(hwnd, 2) '只有2才表示找下一个窗口
GetWindowText hwnd, str1, Len(str1)
SetWindowText hwnd, "我改变了改钮2"
Loop
要在模块里定义:
Public Declare Function GetNextWindow Lib "user32" Alias "GetWindow" (ByVal hwnd As Long, ByVal wFlag As Long) As Long
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Public Declare Function FindWindowa Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function GetForegroundWindow Lib "user32" () As Long
Public Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long
Public Declare Function GetDlgItem Lib "user32" (ByVal hDlg As Long, ByVal nIDDlgItem As Long) As Long
Dim hwnd As Long
Dim str1 As String, len1 As Long
'hwnd = FindWindowa("ThunderRT6FormDC", "Form1") '编译成EXE用这句,
hwnd = FindWindowa("ThunderFormDC", "Form1") '在调试的时候用这句.
str1 = Space(255) '定义接收字串.
GetWindowText hwnd, str1, 1024
Do While hwnd <> 0
hwnd = GetNextWindow(hwnd, 2) '只有2才表示找下一个窗口
len1 = GetWindowText(hwnd, str1, Len(str1))
If (InStr(1, str1, "API", 1) > 0) Then
Exit Do
End If
Loop
SetWindowText hwnd, "我把API阅读器的标题改变了"
hwnd = GetNextWindow(hwnd, 5) '5表示子窗口
Do While hwnd <> 0
hwnd = GetNextWindow(hwnd, 2) '只有2才表示找下一个窗口
GetWindowText hwnd, str1, Len(str1)
SetWindowText hwnd, "我改变了改钮2"
Loop
要在模块里定义:
Public Declare Function GetNextWindow Lib "user32" Alias "GetWindow" (ByVal hwnd As Long, ByVal wFlag As Long) As Long
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Public Declare Function FindWindowa Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function GetForegroundWindow Lib "user32" () As Long
Public Declare Function SetWindowText Lib "user32" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long
Public Declare Function GetDlgItem Lib "user32" (ByVal hDlg As Long, ByVal nIDDlgItem As Long) As Long
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
我装不上IE7....
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询