Webbrowser Control 没有 Hwnd 属性 !!! 请看: http://msdn.microsoft.com/library/default.asp?url=/workshop/browser/webbrowser/reflist_vb.asp另外, MSDN 上已有 这个问题的说明:PRB: Obtaining the HWND for the WebBrowser Control (Q244310) http://support.microsoft.com/default.aspx?scid=kb;en-us;Q244310
那怎么办???我需要HWND属性啊!!!
sonicdater(发呆呆(我答问题*不吵架*因为我呆)) 已经提供解决方法了:Visual Basic developers can use the following code, which takes the HWND of the hosting form and examines all its children until it finds the window with a window class of "Shell Embedding". This is the topmost window of the WebBrowser control. CAUTION: The Internet Explorer window class name may change in future browser versions. Use this workaround with care. Option Explicit Public Const GW_HWNDNEXT = 2 Public Const GW_CHILD = 5 Public Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long Public Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As LongPublic Function GetBrowserWindow(hwndBrowserContainer As Long) As Long Dim RetVal As Long Dim Result As Long Dim hwndChild, hwndPeer As Long Dim ClassString As String * 256
hwndPeer = GetWindow(hwndBrowserContainer, GW_CHILD) While (Result = 0) And (hwndPeer <> 0) hwndPeer = GetWindow(hwndPeer, GW_HWNDNEXT) RetVal = GetClassName(hwndPeer, ClassString, 256) If hwndPeer <> 0 Then RetVal = GetClassName(hwndPeer, ClassString, 256) If Left$(ClassString, InStr(ClassString, Chr$(0)) - 1) = "Shell Embedding" Then Result = 1 End If End If Wend
GetBrowserWindow = hwndChild End Function Please note that neither of these techniques are needed when you automate Internet Explorer. For automation, C++ and Visual Basic users can both use the HWND property of the InternetExplorer object.
请看:
http://msdn.microsoft.com/library/default.asp?url=/workshop/browser/webbrowser/reflist_vb.asp另外, MSDN 上已有 这个问题的说明:PRB: Obtaining the HWND for the WebBrowser Control (Q244310)
http://support.microsoft.com/default.aspx?scid=kb;en-us;Q244310
已经提供解决方法了:Visual Basic developers can use the following code, which takes the HWND of the hosting form and examines all its children until it finds the window with a window class of "Shell Embedding". This is the topmost window of the WebBrowser control. CAUTION: The Internet Explorer window class name may change in future browser versions. Use this workaround with care.
Option Explicit Public Const GW_HWNDNEXT = 2
Public Const GW_CHILD = 5
Public Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Public Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As LongPublic Function GetBrowserWindow(hwndBrowserContainer As Long) As Long
Dim RetVal As Long
Dim Result As Long
Dim hwndChild, hwndPeer As Long
Dim ClassString As String * 256
hwndPeer = GetWindow(hwndBrowserContainer, GW_CHILD)
While (Result = 0) And (hwndPeer <> 0)
hwndPeer = GetWindow(hwndPeer, GW_HWNDNEXT)
RetVal = GetClassName(hwndPeer, ClassString, 256)
If hwndPeer <> 0 Then
RetVal = GetClassName(hwndPeer, ClassString, 256)
If Left$(ClassString, InStr(ClassString, Chr$(0)) - 1) = "Shell Embedding" Then
Result = 1
End If
End If
Wend
GetBrowserWindow = hwndChild
End Function
Please note that neither of these techniques are needed when you automate Internet Explorer. For automation, C++ and Visual Basic users can both use the HWND property of the InternetExplorer object.
y = (Screen.Height / Screen.TwipsPerPixelX) \ 2
SetCursorPos x, y '把鼠标移到WEBBROWSER上
GetCursorPos point
hwnd = WindowFromPoint(point.x, point.y) '获得鼠标下面的窗体的句柄
有效吗?
WindowFromPoint是API
还是VB自带函语句?
SetCursorPos
GetCursorPos
都是 win32 api .你还是 照着 微软的 方法做吧