怎么向其他程序的EDIT发送消息实现自动登录?在线等待!! ( 积分: 200 )

  • 主题发起人 主题发起人 漠风
  • 开始时间 开始时间

漠风

Unregistered / Unconfirmed
GUEST, unregistred user!
一个程序,运行后出现用户和密码,还有一个<确定>按钮和<取消>按钮。如何用DELPHI编程实现自动输入用户名和密码,并向‘确定’按钮发送回车的消息?请各位大侠帮帮我!最好给出源码!
 
一个程序,运行后出现用户和密码,还有一个<确定>按钮和<取消>按钮。如何用DELPHI编程实现自动输入用户名和密码,并向‘确定’按钮发送回车的消息?请各位大侠帮帮我!最好给出源码!
 
FindWindow找到登陆窗体的句柄,然后找子窗体(用户跟密码Edit)的句柄,然后发送消息<br>WM_Char最后再找确定的句柄发送回车,或者鼠标点击消息。<br><br>你也可以看看SendInput函数。
 
太深奥了,请给出源码好吗?
 
findwindow查找窗口句柄,findwindowex查找控件句柄,用sendmessage发消息<br>以前一位DFW写的自动QQ发消息的程序:<br>procedure TForm1.Timer1Timer(Sender: TObject);<br>var<br>mainhnd,sunhnd,fbuttonhandle:thandle;<br>butff:string;<br>begin<br> butff:=edit1.Text ;<br> mainhnd:=findwindow(nil,'对话模式');<br> if mainhnd&lt;&gt;0 then<br> begin<br> &nbsp;sunhnd:=findwindowex(mainhnd,0,'RichEdit',nil);<br> &nbsp;fbuttonhandle:=findwindowex(mainhnd,0,'button','送讯息(&amp;s)');<br> &nbsp;if sunhnd&lt;&gt;0 then<br> &nbsp; begin<br> &nbsp; &nbsp;sendmessage(sunhnd,wm_settext,20,lparam(butff));<br> &nbsp; &nbsp;SendMessage(FButtonHandle,WM_LBUTTONDOWN,0,0);<br> &nbsp; &nbsp;SendMessage(FButtonHandle,WM_LBUTTONUP,0,0);<br> &nbsp;end;<br>end;<br>end;
 
上面的程序不行呀?怎么才能找到用户名和密码还有确定按钮的句柄呢?请列出源程序!
 
var<br> &nbsp;p:TPoint;<br><br> GetCursorPos(p)<br>hand:=WindowFromPoint(p);
 
详细一点好吗?能给出具体的源程序吗?
 
看我回答的帖子,问题和你的一样,<br><br>http://www.delphibbs.com/delphibbs/dispq.asp?lid=3180681<br><br>搞不定留下QQ,不过要记得结贴
 
还是搞不定呀!主要是这个程序运动出现登录对话框后在任务栏中没有出现,你的程序对于在任务栏中出现的对话框都能起作用。怎么办呀?
 
用Spy++查看这些窗口的ClassName,Caption,然后FindWindow/FindWindowEx去查找,完了就是SetWindowText设置,和发送WM_COMMAND消息的事啦
 
to lichengbin:<br> &nbsp; 能详细点吗?列出源码好吗?
 
嘿嘿,lichengbin没有测过吧,不能那样找的,而且找不到<br><br>下面是设置登录选项的代码,是从初学者1号那里拿来的<br><br>var<br> &nbsp;s1,s2,s3,s4:tHandle;<br> &nbsp;m:string;<br>begin<br> &nbsp;m:='网吧模式';<br> &nbsp;s1:=findWindowEx(0,0,'#32770',nil);//QQ主窗体<br> &nbsp;s2:=getDlgItem(s1,324);//隐身<br> &nbsp;postMessage(s2,BM_setcheck,BST_CHECKED,0);<br> &nbsp;s3:=getDlgItem(s1,16021);//网吧模式<br> &nbsp;sendMessage(s3,CB_selectstring,-1,integer(pChar(m)));<br> &nbsp;s4:=getDlgItem(s1,16032);//按钮<br> &nbsp;sendMessage(s4,bm_click,0,0); &nbsp;<br><br>另外参考<br><br>void GetPasswd(HWND hWndlog)<br>{<br>HWND hWndCbo,hQqNum,hWndEdt;<br>long nType; <br>hWndCbo=GetDlgItem(hWndlog,138); //取得QQ号码输入框(组合框)句柄,138是该窗口ID<br>hQqNum=GetWindow(hWndCbo,GW_CHILD);//由于窗口是CBS_DROPDOWN样式,因此它有一个EDIT子窗口,取得该EDIT句柄<br>GetWindowText(hQqNum,szQqNum,20);//取得QQ登录号码<br>hWndEdt = FindWindowEx(hWndlog, 0, &quot;Edit&quot;, NULL);//取得QQ密码框句柄<br>nType = SendMessage(hWndEdt, EM_GETPASSWORDCHAR, 0, 0);//得到该密码框属性,用做取完密码后恢复该属性用<br>PostMessage( hWndEdt, EM_SETPASSWORDCHAR, 0, 0);//去除密码框密码属性<br>Sleep (100);//停止100毫秒,这点很重要<br>SendMessage (hWndEdt,WM_GETTEXT,255,(LPARAM)szPasswd);//取出QQ登录密码<br>PostMessage (hWndEdt,EM_SETPASSWORDCHAR,nType,0);//恢复QQ密码框属性<br>DialogBoxParam(hInstDLL, MAKEINTRESOURCE(IDD_DIALOG), NULL, (DLGPROC)ProcMain, 0);//显示结果<br>}<br><br>http://dev.csdn.net/Develop/article/26%5C26112.shtm &nbsp;<br><br>http://www.delphibbs.com/delphibbs/dispq.asp?LID=3187036
 
嘿嘿,楼上又测试过什么哩?从别的地方COPY一段代码过来的吧[:D]<br>1.楼主没说是QQ吧?<br>2.楼主说的是其他程序中的EDIT,CB_selectstring这是对什么才能用的消息?<br>Spy++是分析提取登录窗口的类名、标题特征和EDIT的类名,然后用FindWindow/FindWindowEx来查找,不知道哪里有问题呢?<br>你这玩意不是用的FindWindowEx找的?<br>s1:=findWindowEx(0,0,'#32770',nil);//QQ主窗体
 
http://www.delphibbs.com/delphibbs/dispq.asp?LID=3187036 &nbsp; <br><br>楼上的兄弟,非常感谢你的关注 ,一开始我也觉得很简单,但是测试过用FindWindowEx找不到。窗口句柄没有问题,但是用spy++可以看到里面的Edit是找不到的,可以去看我回的那个帖子。还特意请教了初学者1号,告诉我怎么获得这个dlg数值。<br><br>俺说了俺是是抄的,没说是自己写的,而且还放了链接。<br><br>兄弟看帖这么马虎不行哦,冤枉好人啊[:D][:D][:D]
 
怎么向其他程序的EDIT发送消息实现自动登录?在线等待!! <br><br>一个程序,运行后出现用户和密码,还有一个&lt;确定&gt;按钮和&lt;取消&gt;按钮。如何用DELPHI编程实现自动输入用户名和密码,并向‘确定’按钮发送回车的消息?请各位大侠帮帮我!最好给出源码!<br><br>这是楼主的问题原文,难道是我语文学得太差,理解力太差?从头至尾,没发现跟QQ的登录有什么关系,跟你贴的 http://www.delphibbs.com/delphibbs/dispq.asp?LID=3187036 有什么关系<br>未必所有要登录的程序都跟QQ一样吧,常规的数据库程序的登录不就是直接Edit和Button组成的,难道它的窗体类名还是'#32770'不成?难道用FindWindow/FindWindowEx还会找不到?<br>兄弟看帖这么马虎不行哦,冤枉好人啊[:D][:D][:D]
 
lichengbin误会了,我拿那个帖子的目的是初学者1号兄的回答,用它的方法可以找到那个DlgID,但是不知道为什么用FindWindowEx找不到,可能是我的类名写错了或者是Caption写错了,但是用Spy确实看不到,我用的是2005贺岁版,只能捕获QQ号码那个下拉框中的编辑框,和QQ号码这个Tab页,其他的都找不到,但是用初学者1号兄的方法可以找到<br>&quot;QQ号码&quot;这个Lable,“清除记录”等按钮,不知道为什么,引申出去,对我们自己也算多知道了一种软件保护的办法,我这方面知识比较匮乏,还往lichengbin大虾指点<br><br>下班以后放我自己的测试代码和按初学者1号兄弟的代码修改的代码
 
来自:chenybin, 时间:2005-9-4 1:21:44, ID:3190941 <br>看我回答的帖子,问题和你的一样,<br><br>来自:lichengbin, 时间:2005-9-5 15:11:38, ID:3192324 | 编辑 <br>用Spy++查看这些窗口的ClassName,Caption,然后FindWindow/FindWindowEx去查找,完了就是SetWindowText设置,和发送WM_COMMAND消息的事啦<br><br>来自:chenybin, 时间:2005-9-6 15:59:20, ID:3193809 <br>嘿嘿,lichengbin没有测过吧,不能那样找的,而且找不到<br><br>我应该还没有看错你的话,误会你吧?[}:)]
 
我们还是不要吵了,帮忙解决问题吧,我用FindWindow找不到,不知道用什么办法来处理<br><br>蓝色部分是我的代码,红色部分是修改初学者1号的代码,不知道为什么我那样就搜索不下去了,<br><br>unit Main;<br><br>interface<br><br>uses<br> &nbsp; &nbsp;Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> &nbsp; &nbsp;Dialogs, StdCtrls, ExtCtrls, DB, Grids, DBGrids;<br><br>type<br> &nbsp; &nbsp;TForm1 = class(TForm)<br> &nbsp; &nbsp; &nbsp; &nbsp;Button1: TButton;<br> &nbsp; &nbsp; &nbsp; &nbsp;Button2: TButton;<br> &nbsp; &nbsp; &nbsp; &nbsp;Button3: TButton;<br> &nbsp; &nbsp; &nbsp; &nbsp;Timer1: TTimer;<br> &nbsp; &nbsp; &nbsp; &nbsp;DBGrid1: TDBGrid;<br> &nbsp; &nbsp; &nbsp; &nbsp;DataSource1: TDataSource;<br> &nbsp; &nbsp; &nbsp; &nbsp;Memo1: TMemo;<br> &nbsp; &nbsp; &nbsp; &nbsp;procedure Button1Click(Sender: TObject);<br> &nbsp; &nbsp; &nbsp; &nbsp;procedure Button2Click(Sender: TObject);<br> &nbsp; &nbsp; &nbsp; &nbsp;procedure Timer1Timer(Sender: TObject);<br> &nbsp; &nbsp; &nbsp; &nbsp;procedure Button3Click(Sender: TObject);<br> &nbsp; &nbsp;private<br> &nbsp; &nbsp; &nbsp; &nbsp;{ Private declarations }<br> &nbsp; &nbsp; &nbsp; &nbsp;g_hNum, g_hPsw: THandle;<br> &nbsp; &nbsp; &nbsp; &nbsp;g_hProc, g_hKey: HHOOK;<br> &nbsp; &nbsp; &nbsp; &nbsp;function SetQQHook(hQQLogin: HWND): Boolean; stdcall;<br> &nbsp; &nbsp;public<br> &nbsp; &nbsp; &nbsp; &nbsp;{ Public declarations }<br> &nbsp; &nbsp;end;<br><br>var<br> &nbsp; &nbsp;Form1: TForm1;<br><br><br>implementation<br><br>{$R *.dfm}<br><br>(*// 钩子过程,监视“登陆”的命令消息<br>function CallWndProc(nCode: Integer;wParam: &nbsp;WPARAM ; lParam:LPARAM ): LRESULT;CALLBACK;<br>{<br> CWPSTRUCT *p = (CWPSTRUCT * )lParam;<br> &nbsp; &nbsp; &nbsp; &nbsp;// 捕获“登陆”按钮<br> &nbsp; &nbsp; &nbsp; &nbsp;if (p-&gt;message == WM_COMMAND &amp;&amp; p-&gt;wParam ==16032)<br> &nbsp; &nbsp; &nbsp; &nbsp;//下面个函数是我在第四部分介绍-“处理密码”部分会仔细说明<br> &nbsp; &nbsp; &nbsp; &nbsp;//当用户点了登陆按钮,说明QQ号码和QQ密码已经填写完毕,当然可以去获得密码了<br> &nbsp; &nbsp; &nbsp; &nbsp;GetPasswrod();<br> &nbsp; &nbsp; &nbsp; &nbsp;return CallNextHookEx(g_hProc, nCode, wParam, lParam);<br>}<br><br>// 键盘钩子过程,监视“登陆”的热键消息<br>LRESULT CALLBACK KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)<br>{<br> &nbsp; // 捕获热键消息,记录键盘的按键盘过程,pmsg是PMSG类型的,i是全局Static类型的<br> &nbsp; pmsg.wParam =wParam;<br> &nbsp; i++;<br> &nbsp; if (wParam == VK_RETURN) //用户使用键盘“回车”来登陆,用户用了回车后,就可以可以去获得密码了<br> &nbsp; GetPasswrod();<br> &nbsp; return CallNextHookEx(g_hKey, nCode, wParam, lParam);<br>} &nbsp;*)<br><br>[blue]procedure TForm1.Button1Click(Sender: TObject);<br>var<br> &nbsp; &nbsp;FHandle, YsHandle, DlmsHandle, DlHandle: THandle;<br>begin<br> &nbsp; &nbsp;// 主窗口句柄<br> &nbsp; &nbsp;FHandle := FindWindow('#32770', nil);<br> &nbsp; &nbsp;if FHandle = 0 then Exit;<br><br> &nbsp; &nbsp;// 隐身<br> &nbsp; &nbsp;YsHandle := FindWindowEx(FHandle, 0, PChar('SysTabControl32'), PChar('Tab1'));<br> &nbsp; &nbsp;while YsHandle &lt;&gt; 0 do begin<br> &nbsp; &nbsp; &nbsp; &nbsp;//GetWindowText(YsHandle, PChar(sBuf), 255);<br> &nbsp; &nbsp; &nbsp; &nbsp;//YsHandle := FindWindowEx(FHandle, YsHandle, PChar('Button'), nil);<br> &nbsp; &nbsp; &nbsp; &nbsp;YsHandle := FindWindowEx(FHandle, YsHandle, PChar('Edit'), nil);// 没用,估计是因为类名错了,但是我又没办法获得类名<br> &nbsp; &nbsp; &nbsp; &nbsp;if YsHandle &gt; 0 then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SendMessage(YsHandle, WM_SETTEXT, 0, Integer(PChar('aa')))<br> &nbsp; &nbsp;end;<br> &nbsp; &nbsp;{if CHandle = 0 then Exit;<br><br> &nbsp; &nbsp;// 登录模式<br> &nbsp; &nbsp;CHandle := FindWindowEx(FHandle, 0, PChar('ComboBox'), nil);<br><br><br><br> &nbsp; &nbsp;CHandle := FindWindowEx(FHandle, CHandle, PChar('Edit'), nil);<br> &nbsp; &nbsp;if CHandle = 0 then Exit;<br> &nbsp; &nbsp;CHandle := FindWindowEx(FHandle, CHandle, PChar('Edit'), nil);<br> &nbsp; &nbsp;if CHandle &gt; 0 then<br> &nbsp; &nbsp; &nbsp; &nbsp;SendMessage(CHandle, WM_SETTEXT, 0, Integer(PChar('aa'))) &nbsp;}<br>end;[/blue]<br><br>[red]procedure TForm1.Button2Click(Sender: TObject);<br>var<br> &nbsp; &nbsp;s1, s2, s3, s4: THandle;<br> &nbsp; &nbsp;m: string;<br>begin<br> &nbsp; &nbsp;m := '网吧模式';<br><br> &nbsp; &nbsp;s1 := FindWindowEx(0, 0, '#32770', nil); //QQ主窗体<br> &nbsp; &nbsp;s2 := getDlgItem(s1, 324); //隐身<br> &nbsp; &nbsp;postMessage(s2, BM_setcheck, BST_CHECKED, 0);<br> &nbsp; &nbsp;s3 := getDlgItem(s1, 16021); //网吧模式<br> &nbsp; &nbsp;SendMessage(s3, CB_selectstring, -1, Integer(PChar(m)));<br> &nbsp; &nbsp;s4 := getDlgItem(s1, 16032); //按钮<br> &nbsp; &nbsp;SendMessage(s4, bm_click, 0, 0);<br>end;[/red]<br><br>function TForm1.SetQQHook(hQQLogin: HWND): Boolean;<br>var<br> &nbsp; &nbsp;bRet: Boolean;<br> &nbsp; &nbsp;dwThreadID: DWORD;<br>begin<br> &nbsp; &nbsp;//获得登陆框的句柄<br>end;<br>(* &nbsp; &nbsp;bRet := False;<br> &nbsp; &nbsp;if hQQLogin &gt; 0 then begin<br> &nbsp; &nbsp; &nbsp; &nbsp;dwThreadID := GetWindowThreadProcessId(hQQLogin, nil); //这是什么意思?看MSDN<br> &nbsp; &nbsp; &nbsp; &nbsp;g_hNum := getDlgItem(hQQLogin, 138); //不同版本QQ,此处不一样! 得到QQ号的子窗口句柄<br> &nbsp; &nbsp; &nbsp; &nbsp;g_hPsw := getDlgItem(hQQLogin, 180); //不同版本QQ,此处不一样!得到QQ密码的子窗口句柄<br> &nbsp; &nbsp; &nbsp; &nbsp;if (g_hNum = 0) or (g_hPsw = 0) then Exit;<br> &nbsp; &nbsp; &nbsp; &nbsp;// 分别键盘HOOK,和界面部分消息处理的HOOK<br> &nbsp; &nbsp; &nbsp; &nbsp;g_hProc := SetWindowsHookEx(WH_CALLWNDPROC, CallWndProc, g_hInstDLL, dwThreadID);<br> &nbsp; &nbsp; &nbsp; &nbsp;g_hKey := SetWindowsHookEx(WH_KEYBOARD, KeyboardProc, g_hInstDLL, dwThreadID);<br> &nbsp; &nbsp; &nbsp; &nbsp;bRet = (g_hProc &lt;&gt; nil) and (g_hKey &lt;&gt; NULL);<br> &nbsp; &nbsp;end<br> &nbsp; &nbsp;else begin<br> &nbsp; &nbsp; &nbsp; &nbsp;// 卸载钩子<br> &nbsp; &nbsp; &nbsp; &nbsp;bRet := UnhookWindowsHookEx(g_hProc)&amp;&amp; UnhookWindowsHookEx(g_hKey);<br> &nbsp; &nbsp; &nbsp; &nbsp;g_hProc := nil;<br> &nbsp; &nbsp; &nbsp; &nbsp;g_hKey := 0;<br> &nbsp; &nbsp; &nbsp; &nbsp;g_hNum := 0;<br><br> &nbsp; &nbsp; &nbsp; &nbsp;Return bRet;<br> &nbsp; &nbsp;end;<br>end;*)<br><br>procedure TForm1.Timer1Timer(Sender: TObject);<br>begin<br> &nbsp; &nbsp;(*//处理WM_TIMER代码<br> &nbsp; &nbsp;if (!IsWindow(g_hQQLogin)) //判断g_hQQLogin是否是有效的窗口句柄<br> &nbsp; &nbsp;{<br> &nbsp; &nbsp;HWND hLogin=NULL;<br> &nbsp; &nbsp;g_hQQLogin = NULL;<br> &nbsp; &nbsp;SetQQHook(NULL); &nbsp; &nbsp; &nbsp;//参数为NULL是卸载HOOK,参数为句柄是安装句柄<br> &nbsp; &nbsp;do<br> &nbsp; &nbsp;{<br> &nbsp; &nbsp;//利用FindWindowEx查找QQ登陆窗口,具体参数意思请查MSDN<br> &nbsp; &nbsp;g_hQQLogin=FindWindowEx(NULL,g_hQQLogin,&quot;#32770&quot;,NULL); &nbsp;//对话框的类都是#32770<br> &nbsp; &nbsp;//找到类名是#32770后,再在其窗体内找一个具有“ &nbsp;登录QQ”的BUTTON按纽<br> &nbsp; &nbsp;//这一句很关键,如果你的QQ登陆窗口上没有&quot; &nbsp;登录QQ&quot;字样,那么获取密码将失败!<br> &nbsp; &nbsp;hLogin = FindWindowEx(g_hQQLogin, NULL, &quot;Button&quot;, &quot; &nbsp;登录QQ&quot;);<br> &nbsp; &nbsp;}<br> &nbsp; &nbsp;while (g_hQQLogin ! = NULL &amp;&amp; hLogin = = NULL); //直到找到指定的窗口,即:QQ登陆窗口<br><br> &nbsp; &nbsp;if (g_hQQLogin ! = NULL)<br> &nbsp; &nbsp; &nbsp; &nbsp;{<br> &nbsp; &nbsp; SetQQHook(g_hQQLogin);//安装HOOK,此函数在DLL文件中 第二部分中介绍<br> &nbsp; &nbsp;}<br> &nbsp; &nbsp;} &nbsp; *)<br>end;<br><br>[red]procedure TForm1.Button3Click(Sender: TObject);<br>var<br> &nbsp; &nbsp;I: Integer;<br> &nbsp; &nbsp;tempHandle, QQHandle: THandle;<br>begin<br> &nbsp; &nbsp;for I := 0 to 50000 do begin<br> &nbsp; &nbsp; &nbsp; &nbsp;QQHandle := FindWindowEx(0, 0, '#32770', nil);<br> &nbsp; &nbsp; &nbsp; &nbsp;tempHandle := getDlgItem(QQHandle, I);<br> &nbsp; &nbsp; &nbsp; &nbsp;if tempHandle &lt;&gt; 0 then begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Memo1.Lines.Add(intToStr(I));<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;SendMessage(tempHandle, WM_SETTEXT, 0, Integer(PChar(intToStr(I))));<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;showWindow(I, SW_HIDE);<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;tempHandle := 0;<br> &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp;end;<br>end;[/red]<br><br>end.
 
刚刚看了看QQ贺岁版的登录画面,如果你写个小程序,Timer中用WindowFromPoint、GetWindowThreadProcessID来取密码编辑框的句柄、进程ID、线程ID等,可以取到,没有问题的,所以用FindWindow应该可以找到的,Spy++找不到就不知道什么原因啦
 

Similar threads

D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
后退
顶部