如何编程模拟点击另一程序的对话框上的按钮,源程见正文!!!!!!!!!!! (100分)

  • 主题发起人 主题发起人 yexiaoming
  • 开始时间 开始时间
Y

yexiaoming

Unregistered / Unconfirmed
GUEST, unregistred user!
程序如下,请大富翁们指教如何改正。<br>&nbsp; &nbsp;Handle := FindWindow('Tmainform', 'test'); &nbsp;<br>&nbsp; if Handle &lt;&gt; 0 then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;。。。。查找别一程序的窗体句柄<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;BtnHandle := Handle;//已取得按钮句柄<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//SendMessage(FButtonHandle, WM_LBUTTONDOWN, 0, 0);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//SendMessage(FButtonHandle, WM_LBUTTONUP, 0, 0);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;PostMessage(FButtonHandle, WM_LBUTTONDOWN, 0, 0);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;PostMessage(FButtonHandle, WM_LBUTTONUP, 0, 0);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//注:改成PostMessage可以跳过<br>&nbsp; &nbsp; &nbsp; //模拟点击另一程序,结果为别一程序弹出对话框,本程序就在此句停住,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//不能执行下一句模拟点击另一程序对话框的程序。<br>&nbsp; &nbsp; &nbsp; &nbsp; Handle := FindWindow('Tform1', 'test'); &nbsp;//对话框窗口查找不到正确的句柄,重点<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if Handle &lt;&gt; 0 then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 。。。。。。。。。。。。。<br>end;
 
用 PostMessage 代替 SendMessage 试试
 
不是postmessage的问题,是你第二次找的句柄不对,不信你可以用spy++ 看看。<br>你找的handle &nbsp;还是你刚才的窗口的。<br>FindWindow 找是有顺序的。
 
有没试过用 FindWindowEX 呢,把 FindWindow 换为 FindWindowEX 试试
 
BtnHandle := Handle;//已取得按钮句柄?<br>button好想有独立的句柄吧,speedbutton之类的好象没有。你用findwindowex找找handle下<br>的子窗口试试。
 
兄弟留下一个箱子,我卖给你一段代码,是我以前写的用来 进行qq 的消息攻击<br>原理就是查找 几个句柄 然后 模拟按钮单击,不过代码比较乱。
 
谢谢 人在昆明 兄,我的mail:yxm@fun.21cn.com<br>我综合一下得出如下结论:<br>用postmessage可以跳过执行下一句,但下一句查找窗口时找不到正确的句柄,可能是<br>Findwindow的问题,改成findwindowex(主句柄,0,'Tform1', 'test')得出的句柄都是0,<br>用另一按钮直接对其正确的句柄(用WinSight 得出)模拟按键,可以关得掉,现在关键问<br>题是如何查找出正确的句柄呢?<br>注:此对话框是窗体形式,类名、标题已知
 
已经发啦,
 
谢谢 人在昆明 兄,我已经看过代码了,我用的方法也差不多,主要查找按钮的方法,<br>程序在正确的窗口句柄下(用WinSight 得出)也可以找到按钮的句柄并模拟点击,但<br>现在就是找不到对话框的正确句柄。可否帮忙指点。。
 
你的意思就是 &nbsp;第一次可以找到句柄,当弹出对话框 之后 找不到对话框的句柄??<br>看了你的代码知道为什么啦!<br>呵呵,原来是这样,<br><br>&nbsp; &nbsp; &nbsp; //模拟点击另一程序,结果为别一程序弹出对话框,本程序就在此句停住,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//不能执行下一句模拟点击另一程序对话框的程序。<br>&nbsp; &nbsp; &nbsp; &nbsp; Handle := FindWindow('Tform1', 'test'); &nbsp;//对话框窗口查找不到正确的句柄,重点<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if Handle &lt;&gt; 0 then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 。。。。。。。。。。。。。<br>你把这段之后的代码 &nbsp;放在 另外一个BUTTONCLICK &nbsp;中触发。呵呵,肯定是啦!
 
TO:人在昆明<br>&nbsp;等弹出对话框后,在另一按钮中作程序如下:可以正常关闭<br>&nbsp; &nbsp; EnumChildWindows(3148, @GetButtonHandle1, Integer(@Handle1));<br>&nbsp; &nbsp;//3148 为弹出对话框后用WinSight 得出<br>&nbsp; &nbsp; FButtonHandle := Handle1;<br>&nbsp; &nbsp; SendMessage(FButtonHandle, WM_LBUTTONDOWN, 0, 0);<br>&nbsp; &nbsp; SendMessage(FButtonHandle, WM_LBUTTONUP, 0, 0);<br>&nbsp; &nbsp;//可以正常关闭,说明查找按钮成功,但对话框窗体的HANDLE不能找出
 
呵呵,就是啦你放在一个事件中触发,<br><br>&nbsp; &nbsp;Handle := FindWindow('Tmainform', 'test'); &nbsp;<br>&nbsp; if Handle &lt;&gt; 0 then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;。。。。查找别一程序的窗体句柄<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;BtnHandle := Handle;//已取得按钮句柄<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//SendMessage(FButtonHandle, WM_LBUTTONDOWN, 0, 0);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//SendMessage(FButtonHandle, WM_LBUTTONUP, 0, 0);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;PostMessage(FButtonHandle, WM_LBUTTONDOWN, 0, 0);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;PostMessage(FButtonHandle, WM_LBUTTONUP, 0, 0);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//注:改成PostMessage可以跳过<br><br>当执行到这里的时候你的对话框弹出了吗??<br><br>但是你却没管就去 操作 &nbsp;弹出的对话框啦!<br><br>&nbsp; &nbsp; &nbsp; //模拟点击另一程序,结果为别一程序弹出对话框,本程序就在此句停住,<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;//不能执行下一句模拟点击另一程序对话框的程序。<br>&nbsp; &nbsp; &nbsp; &nbsp; Handle := FindWindow('Tform1', 'test'); &nbsp;//对话框窗口查找不到正确的句柄,重点<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if Handle &lt;&gt; 0 then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 。。。。。。。。。。。。。<br><br><br>
 
谢谢人在昆明兄的提醒,我用笨办法了,在查找对话框前加SLEEP
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
617
import
I
后退
顶部