vb程序中webbrowser 接受SendMessage 的消息

前端之家收集整理的这篇文章主要介绍了vb程序中webbrowser 接受SendMessage 的消息前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

webbrowser 不能收到SendMessage的消息

主要是因为1webbrowser 的句柄找不到。经过努力搜索,终于解决了。做个记录.


Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long,ByVal wMsg As Long,ByVal wParam As Long,ByVal lParam As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd 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
Const WM_LBUTTONDOWN = &H201
Const WM_LBUTTONUP = &H202
Const MK_LBUTTON = &H1

'获得webbrowser的句柄
Public Function GetBrowserWindow(窗体句柄 As Long) As Long
Dim hwndPeer As Long
hwndPeer = FindWindowEx(窗体句柄,"Shell Embedding",vbNullString)'网上很多帮助就找到这里就结束了,那是不能收到消息的。
hwndPeer = FindWindowEx(hwndPeer,"Shell DocObject View",vbNullString)
hwndPeer = FindWindowEx(hwndPeer,"Internet Explorer_Server",vbNullString)
GetBrowserWindow = hwndPeer
End Function

'按钮单击
Private Sub 命令_Click()
Dim t As String,x As Long,y As Long,w As WebBrowser,wbhwnd As Long,k As Long
x = 537'从WebBrowser控件左上角起0,坐标不是平时left、right、top、height那个坐标,可以直接复制控件到画图里面,看分辨录。
y = 44 * &H10000'弄成高位
wbhwnd = GetBrowserWindow(Form1.hwnd)
k = PostMessage(wbhwnd,WM_LBUTTONDOWN,MK_LBUTTON,ByVal ((y) + x))
k = PostMessage(wbhwnd,WM_LBUTTONUP,(x + (y)))
End Sub

'测试通过。

猜你在找的VB相关文章