积极答复者
VB2010还真比不上VB6,到了2010连个网页都点击不了。为什么没反应?

问题
-
Option Strict Off
Option Explicit On
Imports System.Runtime.InteropServicesImports VB = Microsoft.VisualBasic
Friend Class Form1
Inherits System.Windows.Forms.Form
Private Const xx As Object = 100 '坐标,需要的话请自己修改
Private Const yy As Object = 245
'坐标是指相对于webbrowser控件的坐标
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
Private Const WM_MOUSEMOVE As Long = &H200
Private Const WM_LBUTTONDOWN As Long = &H201
Private Const WM_LBUTTONUP As Long = &H202Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Integer, ByVal nIndex As Integer) As Integer
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Integer, ByVal wCmd As Integer) As Integer
Private Const GW_CHILD As Short = 5
Private Const GW_HWNDNEXT As Short = 2
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Integer, ByVal lpClassName As String, ByVal nMaxCount As Integer) As Integer
Private WebHwnd As Long
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Integer)Private Sub Command1_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command1.Click
Dim h As Integer
Dim S As String
If Timer1.Enabled = False Then
h = GetWindow(Me.Handle.ToInt32, GW_CHILD)
While h <> 0
S = New String(vbNullChar, 256)
GetClassName(h, S, 256)
S = VB.Left(S, InStr(S, vbNullChar) - 1)
If S = "Shell Embedding" Then
WebHwnd = GetWindow(GetWindow(h, GW_CHILD), GW_CHILD)
End If
h = GetWindow(h, GW_HWNDNEXT)
End WhileTimer1.Enabled = True
Command1.Text = "暂停"
Else
Command1.Text = "开始"
Timer1.Enabled = False
End IfEnd Sub
Private Sub Command2_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command2.Click
PostMessage(WebHwnd, WM_LBUTTONDOWN, 0, MakeLparam(xx, yy))
Sleep(10)
PostMessage(WebHwnd, WM_LBUTTONUP, 0, MakeLparam(xx, yy))
End SubPrivate Sub Form1_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
Timer1.Enabled = False
Timer1.Interval = 10
Me.Show()
WebBrowser1.Navigate(New System.Uri("http://guba.eastmoney.com/topic,000807.html")) '你的网址
Command1.Text = "开始"
Command2.Text = "点击"
End SubPrivate Sub Timer1_Tick(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Timer1.Tick
PostMessage(WebHwnd, WM_MOUSEMOVE, 0, MakeLparam(xx, yy))
End Sub
Private Function MakeLparam(ByVal x As Short, ByVal y As Short) As Integer
Dim h As String
Dim l As String
l = Hex(x)
h = Hex(y)
l = New String("0", 4 - Len(l)) & l
h = New String("0", 4 - Len(h)) & h
MakeLparam = CDec("&h" & h & l)
End FunctionEnd Class
答案
-
这方法不是说了IE5.01之后可能就失效么?有现成的HtmlElement类怎么不用?
The following is signature, not part of post
Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
Visual C++ MVP- 已标记为答案 Youen ZenModerator 2012年5月30日 8:12
全部回复
-
这方法不是说了IE5.01之后可能就失效么?有现成的HtmlElement类怎么不用?
The following is signature, not part of post
Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
Visual C++ MVP- 已标记为答案 Youen ZenModerator 2012年5月30日 8:12
-
这方法不是说了IE5.01之后可能就失效么?有现成的HtmlElement类怎么不用?
你能在http://club.china.com/data/thread/1011/2740/53/09/3_1.html 下面文本框输入文字的。。不用模拟API。
The following is signature, not part of post
Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
Visual C++ MVP -
你的回复和你的问题没有一点关系,我能不能做什么和你的程序能不能做什么是两回事。
The following is signature, not part of post
Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
Visual C++ MVP