如何利用FindWindowEx点击网页弹出对话框确定按钮

netfox2003 2012-07-18 06:24:03
如何利用FindWindowEx点击网页弹出对话框确定按钮
按照一般方法
Dim PW, CW
PW = FindWindow("#32770", vbNullString)
CW = FindWindowEx(pk, ByVal 0&, vbNullString, "确定")
'CW = FindWindowEx(pk, ByVal 0&,"Button" ,vbNullString)
SendMessage pp, BM_CLICK, 0, 0

结果发现失败!

请教正确写法.....
...全文
825 23 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
23 条回复
切换为时间正序
请发表友善的回复…
发表回复
zh618 2014-07-08
  • 打赏
  • 举报
回复
本人编写了一个网络对话框自动回复程序:复上声明和实现函数代码 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 Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long 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 PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long Private Const WM_LBUTTONDOWN = &H201 Private Const WM_LBUTTONUP = &H202 Dim msghWnd As Long, iWnd As Long Dim tc_no As Integer Private Sub Timer1_Timer() Dim i As Long Dim webstr As String If Text1.Text = "" Then webstr = "来自网页的消息" '定义标题 Else webstr = Text1.Text End If ihWnd = FindWindow(vbNullString, webstr) '以标题查找对话框 If ihWnd > 0 Then tc_no = tc_no + 1 Label_no.Caption = "检测到弹窗" + CStr(tc_no) + "次" msghWnd = FindWindowEx(ihWnd, 0, "button", "确定") '找到确定按钮 'SetForegroundWindow msghWnd '实现鼠标点击操作 PostMessage msghWnd, WM_LBUTTONDOWN, 0, ByVal (1 + 1 * 65536) PostMessage msghWnd, WM_LBUTTONUP, 0, ByVal (1 + 1 * 65536) End If End Sub
zydscaline 2012-08-01
  • 打赏
  • 举报
回复
还不结贴
netfox2003 2012-07-21
  • 打赏
  • 举报
回复
问题解决了,思路:写类定时器让它Form外就行,谢谢大家.
xjg811 2012-07-19
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 的回复:]
CW = FindWindowEx(pk, ByVal 0&, vbNullString, "确定")
这句出问题
[/Quote]
您的“pk” 应为 pw

还有 您在一楼的 SendMessage pp, BM_CLICK, 0, 0
其中“pp” 应为 cw

我不知道您的pk与pp是什么??
xjg811 2012-07-19
  • 打赏
  • 举报
回复
各网页不一样。
也许我遇到的是容易的,我是用Timer1_Timer解决。
用hook要麻烦些。
xjg811 2012-07-19
  • 打赏
  • 举报
回复
能否将网页告诉我?
zydscaline 2012-07-19
  • 打赏
  • 举报
回复
[Quote=引用 16 楼 的回复:]
引用 15 楼 的回复:
有人说:在VB的webbrowser中弹出的对话框是模式对话框,弹出后VB代码处于暂停状态,又怎么能去查找对话框的句柄呢。
那思路又该是怎样呢?

看来你不知道钩子,你要先学钩子,钩子的作用可以对付“弹出后VB代码处于暂停状态”

在本例中Timer1_Timer相当于简单的钩子
[/Quote]我试过在WebBrowser中用Timer控件来找网页弹出的提示或警告,但是,不成功,所以,这个钩子不行啊,要换个,
xjg811 2012-07-19
  • 打赏
  • 举报
回复
不好意思,我也是菜鸟……
我学习API很吃力。我菜鸟的体会是,1.钩子难学;2.sendmessage函数是最复杂的API。
所以简单的登陆问题,可能很不简单!
我说的可能不对,请路过的老师指点。
xjg811 2012-07-19
  • 打赏
  • 举报
回复
因为网页为了点击率等原因,努力防止程序自动登陆,用的招式各家不一样。
所以程序自动登陆要具体分析,区别对待。

我在3楼与11楼说了,你说出网页,我帮你搞定
你不说,我没法
xjg811 2012-07-19
  • 打赏
  • 举报
回复
[Quote=引用 15 楼 的回复:]
有人说:在VB的webbrowser中弹出的对话框是模式对话框,弹出后VB代码处于暂停状态,又怎么能去查找对话框的句柄呢。
那思路又该是怎样呢?
[/Quote]
看来你不知道钩子,你要先学钩子,钩子的作用可以对付“弹出后VB代码处于暂停状态”

在本例中Timer1_Timer相当于简单的钩子
netfox2003 2012-07-19
  • 打赏
  • 举报
回复
有人说:在VB的webbrowser中弹出的对话框是模式对话框,弹出后VB代码处于暂停状态,又怎么能去查找对话框的句柄呢。
那思路又该是怎样呢?
赵4老师 2012-07-19
  • 打赏
  • 举报
回复
netfox2003 2012-07-19
  • 打赏
  • 举报
回复
其实pw=pk,cw=pp,不好意思写错了
netfox2003 2012-07-18
  • 打赏
  • 举报
回复
我就像楼上的方法写的,还是确定不了.还是谢谢楼上
xjg811 2012-07-18
  • 打赏
  • 举报
回复


加一个timer1
1.在适当的地方加
Timer1.Enabled = True
Timer1.Interval = 100
2.
Sub Timer1_Timer()
Dim PW, CW
PW = FindWindow("#32770", vbNullString)
if pw<>0 then
CW = FindWindowEx(pw, ByVal 0&, vbNullString, "确定")
SendMessage cw, BM_CLICK, 0, 0
end if
end sub
3. 在适当的地方加
Timer1.enabled=false

xjg811 2012-07-18
  • 打赏
  • 举报
回复
vbaTimer1应为Timer1
xjg811 2012-07-18
  • 打赏
  • 举报
回复
加一个time1
1.在适当的地方加
Timer1.Enabled = True
Timer1.Interval = 100
2.
Sub vbaTimer1_Timer()
Dim PW, CW
PW = FindWindow("#32770", vbNullString)
if pw<>0 then
CW = FindWindowEx(pw, ByVal 0&, vbNullString, "确定")
SendMessage pp, BM_CLICK, 0, 0
end if
end sub
3. 在适当的地方加
vbaTimer1.enabled=false

祝你成功
netfox2003 2012-07-18
  • 打赏
  • 举报
回复
就是在webbrowser内打开一个页面就弹出一个对话框.对话框内有一个“确定”
netfox2003 2012-07-18
  • 打赏
  • 举报
回复
CW = FindWindowEx(pk, ByVal 0&, vbNullString, "确定")
这句出问题
  • 打赏
  • 举报
回复
我给你个例子吧,比如我要关闭QQ2012,现在我写代码如下:
#include <windows.h>
int main(){
HWND hQQWnd= FindWindow(NULL, TEXT("QQ2012"));//如果你是其它版本的话,你明白的
SendMessage(hQQWnd, WM_CLOSE, 0, 0);
}

不知道是否解决了LS的问题,求楼主给分,给分是好人,好人一生平安
加载更多回复(3)

1,488

社区成员

发帖
与我相关
我的任务
社区描述
VB API
社区管理员
  • API
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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