句柄问题!高手请进!100分送上!

kwxx 2002-03-29 08:46:11
使用WebBrowser控件时
调用Hwnd属性时,出现"HWND"的"IWebBrowser2"方法错误
这是怎么回事?
高手赐教!!!
...全文
31 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
kwxx 2002-03-30
  • 打赏
  • 举报
回复
TO:LOU_DF(ldf)
有效吗?
WindowFromPoint是API
还是VB自带函语句?
lou_df 2002-03-30
  • 打赏
  • 举报
回复
x = Screen.Width / Screen.TwipsPerPixelX \ 2
y = (Screen.Height / Screen.TwipsPerPixelX) \ 2
SetCursorPos x, y '把鼠标移到WEBBROWSER上
GetCursorPos point
hwnd = WindowFromPoint(point.x, point.y) '获得鼠标下面的窗体的句柄
TechnoFantasy 2002-03-30
  • 打赏
  • 举报
回复
你说的是IE内的工具栏这样控件还是页面里面的控件,如果是后者可能无法获得,如果是前者,理论上获得窗口局柄就可以获得里面的控件的局柄,不过我没有试过在IE中的编程
kwxx 2002-03-30
  • 打赏
  • 举报
回复
可以取得窗口内的一个控件的HWND是吗??

谢谢了
TechnoFantasy 2002-03-30
  • 打赏
  • 举报
回复
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 Long

Public 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.
kwxx 2002-03-30
  • 打赏
  • 举报
回复
那怎么办???

我需要HWND属性啊!!!
sonicdater 2002-03-30
  • 打赏
  • 举报
回复
WindowFromPoint
SetCursorPos
GetCursorPos
都是 win32 api .

你还是 照着 微软的 方法做吧
TechnoFantasy 2002-03-29
  • 打赏
  • 举报
回复
HWND是InternetExplorer对象属性
sonicdater 2002-03-29
  • 打赏
  • 举报
回复
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
TechnoFantasy 2002-03-29
  • 打赏
  • 举报
回复
你的IE版本是什么
happybeyond 2002-03-29
  • 打赏
  • 举报
回复
关注!
kwxx 2002-03-29
  • 打赏
  • 举报
回复
有什么代码???

一有关于它句柄的代码无论什么就出错啊!!!

例如a=WebBrowser1.Hwnd就OVER
sonicdater 2002-03-29
  • 打赏
  • 举报
回复
能把 代码帖出来吗?
zyl910 2002-03-29
  • 打赏
  • 举报
回复
关注!

742

社区成员

发帖
与我相关
我的任务
社区描述
VB 版八卦、闲侃,联络感情地盘,禁广告帖、作业帖
社区管理员
  • 非技术类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧