|
楼主 |
发表于 2006-4-9 01:45
|
显示全部楼层
answer
Label是轻量级控件,当然无法获得句柄。
' 找到程序的窗口句柄后,发个消息
' 这个贴子的IE窗口别关,把代码复制到窗体代码中单击Command1就能获得地址栏中的URL。
Option Explicit
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Const WM_GETTEXT = &HD
Private Sub Command1_Click()
Dim Handle As Long
Dim wndText As String
wndText = Space(255)
Handle = FindWindow("IEFrame", "在WINDOWS中,如何读取其它应用程序窗口中的数据? - Microsoft Internet Explorer")
Handle = FindWindowEx(Handle, 0&, "WorkerW", vbNullString)
Handle = FindWindowEx(Handle, 0&, "ReBarWindow32", vbNullString)
Handle = FindWindowEx(Handle, 0&, "ComboBoxEx32", vbNullString)
Handle = FindWindowEx(Handle, 0&, "ComboBox", vbNullString) ' 获得窗口句柄
Handle = FindWindowEx(Handle, 0&, "Edit", vbNullString)
SendMessage Handle, WM_GETTEXT, 256, ByVal wndText
wndText = Left(wndText, InStr(wndText, Chr(0)))
Debug.Print wndText
End Sub |
|