如何让程序自已完输入功能?(20分)

  • 主题发起人 主题发起人 ANDREWWUYOU
  • 开始时间 开始时间
A

ANDREWWUYOU

Unregistered / Unconfirmed
GUEST, unregistred user!
就是启动一个程序后,再启动另外一个程序让他自动完成输入前面启动的程序的用户名和密码后进入界面。(因本人是初学者没有好多分请见谅!)
 
这个简单使用消息<br>sendmessage(bhandle,em_setsel,0,0);<br>sendmessage(bhandle,em_replacesel,0,integer(@str));<br><br>其中bhandle是你要写入内容的edit框的句柄<br>str是你要写入的内容
 
你好朋友能不能详细一点说我是初学者
 
LRESULT SendMessage(<br>&nbsp; &nbsp; HWND hWnd, // handle of destination window<br>&nbsp; &nbsp; UINT Msg, // message to send<br>&nbsp; &nbsp; WPARAM wParam, // first message parameter<br>&nbsp; &nbsp; LPARAM lParam // second message parameter<br>&nbsp; &nbsp;);<br>edtTest: TEdit;<br>sendmessage(edtTest.Handle, wm_keydown, VK_F2, 0);<br>第三个参数为:键值,0时看'四'; 第四个参数为要传的内容地址;<br>integer(@str)是取地址
 
模拟按键即可,我来晚了,<br>qq:71892967欢迎交流<br>
 
"其中bhandle是你要写入内容的edit框的句柄"<br>那句柄又要怎么找呢
 
学习中,帮忙提前~~
 
看看这个偶写的自动发qq或uc消息的(要打开对聊),发送表情的没有写完<br>可能对你有用<br>unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br>&nbsp; Dialogs, Buttons, StdCtrls, ExtCtrls,SHELLAPI;<br><br>type<br>&nbsp; TForm1 = class(TForm)<br>&nbsp; &nbsp; Panel1: TPanel;<br>&nbsp; &nbsp; RadioGroup1: TRadioGroup;<br>&nbsp; &nbsp; RB_QQ: TRadioButton;<br>&nbsp; &nbsp; RB_UC: TRadioButton;<br>&nbsp; &nbsp; Edit_QQ: TEdit;<br>&nbsp; &nbsp; Edit_uc: TEdit;<br>&nbsp; &nbsp; GroupBox1: TGroupBox;<br>&nbsp; &nbsp; Memo1: TMemo;<br>&nbsp; &nbsp; Panel2: TPanel;<br>&nbsp; &nbsp; Sbtn_send: TSpeedButton;<br>&nbsp; &nbsp; Sbtn_stop: TSpeedButton;<br>&nbsp; &nbsp; Sbtn_close: TSpeedButton;<br>&nbsp; &nbsp; StaticText1: TStaticText;<br>&nbsp; &nbsp; Ed_time: TEdit;<br>&nbsp; &nbsp; Timer1: TTimer;<br>&nbsp; &nbsp; GroupBox2: TGroupBox;<br>&nbsp; &nbsp; StaticText2: TStaticText;<br>&nbsp; &nbsp; CBox_QQ: TComboBox;<br>&nbsp; &nbsp; CBox_UC: TComboBox;<br>&nbsp; &nbsp; Button1: TButton;<br>&nbsp; &nbsp; procedure RB_QQClick(Sender: TObject);<br>&nbsp; &nbsp; procedure Sbtn_sendClick(Sender: TObject);<br>&nbsp; &nbsp; procedure Ed_timeKeyPress(Sender: TObject; var Key: Char);<br>&nbsp; &nbsp; procedure Sbtn_closeClick(Sender: TObject);<br>&nbsp; &nbsp; procedure Timer1Timer(Sender: TObject);<br>&nbsp; &nbsp; procedure Sbtn_stopClick(Sender: TObject);<br>&nbsp; &nbsp; procedure FormClose(Sender: TObject; var Action: TCloseAction);<br>&nbsp; &nbsp; procedure Button1Click(Sender: TObject);<br>&nbsp; private<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; Form1: TForm1;<br>&nbsp; edit_hd,btn_hd,edit_hd1,myqq:Thandle;<br>&nbsp; str_send:string;<br>&nbsp; qqbq:array[0..49] of string=('/jy','/pz','/se','/fd','/dy','/ll','/hx','/bz',<br>&nbsp; '/shui','/dk','/gg','/fn','/tp','/cy','/wx', '/ng','/ku','/feid',<br>&nbsp; '/zk','/tu','/jk','/lh','/hanx','/db','/shan','/fad','/zt','/xg','/maom','/yb',<br>&nbsp; '/gf','/fan','/yw','/mg','/dx','/wen','/xin','/xs','/hy','/lw','/dh','/sj',<br>&nbsp; '/yj','/ds','/ty','/yl','/qiang','/ruo','/ws','/bb');<br>&nbsp; ucbq:array[0..62] of string=('~!','~@','~#','~$','~%','~^','~&amp;','~*','~(','~)','~-',<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '~=','~+','~|','~/','!@','!#','!$','!%','!^','!&amp;','!*',<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '!(','!)','!_','!+','!|','@~','@!','@#','@$','@%','@^',<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '@*','@(','@)','@_','@+','@|','#~','#!','#@','##','#$',<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '#%','#^','#&amp;','#*','#(','#)','#_','#+','#|','$~','$!',<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; '$@','$#','$$','$%','$^','$&amp;','$*','$(');<br>implementation<br><br>{$R *.dfm}<br><br>procedure TForm1.RB_QQClick(Sender: TObject);<br>begin<br>&nbsp; if TRadioButton(sender).Name='RB_QQ' then begin<br>&nbsp; &nbsp; &nbsp;if TRadioButton(sender).Checked then begin<br>&nbsp; &nbsp; &nbsp; &nbsp;Edit_QQ.Enabled:=true;<br>&nbsp; &nbsp; &nbsp; &nbsp;Edit_UC.Enabled:=false;<br>&nbsp; &nbsp; &nbsp;end else<br>&nbsp; &nbsp; &nbsp; &nbsp;Edit_QQ.Enabled:=false;<br>&nbsp; end else begin<br>&nbsp; &nbsp; &nbsp;if TRadioButton(sender).Checked then begin<br>&nbsp; &nbsp; &nbsp; &nbsp;Edit_UC.Enabled:=true;<br>&nbsp; &nbsp; &nbsp; &nbsp;Edit_QQ.Enabled:=false;<br>&nbsp; &nbsp; &nbsp;end else<br>&nbsp; &nbsp; &nbsp; &nbsp;Edit_UC.Enabled:=false;<br>&nbsp; end;<br>end;<br>function EnumProc(Hwnd: THandle;lparam: LPARAM): boolean; stdcall;<br>var<br>lpText,txt: Array[0..255] of char;<br>begin<br>Result := true;<br>GetClassName(hwnd,@lpText,255);<br>{form1.Memo1.Lines.Add(string(lptext));<br>form1.Memo1.Lines.Add(' &nbsp;');<br>GetWindowText(HWnd,@lptext,255);<br>form1.Memo1.Lines.Add(string(lptext)); }<br>if form1.RB_QQ.Checked then begin<br>&nbsp; if LowerCase(lptext)='richedit' then<br>&nbsp; begin<br>&nbsp; if edit_hd=0 then<br>&nbsp; &nbsp; &nbsp;edit_hd := HWnd<br>&nbsp; else<br>&nbsp; &nbsp; edit_hd1 := HWnd;<br>&nbsp; end;<br>&nbsp; if LowerCase(lptext)='button' then begin<br>&nbsp; &nbsp; &nbsp;GetWindowText(HWnd,@txt,255);<br>&nbsp; &nbsp; &nbsp;if txt='发送(&amp;S)' then<br>&nbsp; &nbsp; &nbsp; &nbsp; btn_hd:= HWnd;<br>&nbsp; end;<br>&nbsp; if LowerCase(lptext)='static' then begin<br>&nbsp; &nbsp;GetWindowText(HWnd,@txt,255);<br>&nbsp; &nbsp;if txt='QQ:103301880' then<br>&nbsp; &nbsp; &nbsp; myqq:= HWnd;<br>&nbsp; end;<br>end else begin<br>&nbsp;if LowerCase(lptext)='tucpredit' then<br>&nbsp; begin<br>&nbsp; edit_hd := HWnd;<br>&nbsp; end;<br>&nbsp; if LowerCase(lptext)='tucbutton' then begin<br>&nbsp; &nbsp; &nbsp;GetWindowText(HWnd,@txt,255);<br>&nbsp; &nbsp; &nbsp;if txt='发送(&amp;S)' then<br>&nbsp; &nbsp; &nbsp; &nbsp; btn_hd:= HWnd;<br>&nbsp; end;<br>&nbsp; if LowerCase(lptext)='tedit' then begin<br>&nbsp; &nbsp;GetWindowText(HWnd,@txt,255);<br>&nbsp; &nbsp;if txt='45778742' then<br>&nbsp; &nbsp; &nbsp; myqq:= HWnd;<br>&nbsp; end;<br>end ;<br>&nbsp; result:=true;<br>end;<br><br>procedure TForm1.Sbtn_sendClick(Sender: TObject);<br>var<br>&nbsp; w_hd:Thandle;<br>&nbsp; i:integer;<br>&nbsp; str_title:string;<br>begin<br>edit_hd:=0;<br>btn_hd:=0;<br>edit_hd1:=0;<br>myqq:=0;<br>&nbsp;if RB_QQ.Checked then<br>&nbsp; str_title:=edit_qq.Text<br>&nbsp;else if RB_UC.Checked then<br>&nbsp; str_title:=edit_UC.Text<br>&nbsp;else begin<br>&nbsp; application.MessageBox('请选择骚扰对象!','提示',MB_ICONINFORMATION+MB_OK);<br>&nbsp; exit;<br>&nbsp;end;<br>&nbsp; W_hd:=FindWIndow(nil,pchar(str_title));<br>&nbsp; if W_hd=0 then begin<br>&nbsp; &nbsp; application.MessageBox('对象不存在!','提示',MB_ICONWARNING+MB_OK);<br>&nbsp; &nbsp; exit;<br>&nbsp; end;<br>&nbsp; if trim(Memo1.Text)='' then begin<br>&nbsp; &nbsp; application.MessageBox('请输入发送内容!','提示',MB_ICONINFORMATION+MB_OK);<br>&nbsp; &nbsp; exit;<br>&nbsp; end else<br>&nbsp; &nbsp;str_send:=memo1.Text;<br>&nbsp; EnumChildWindows(W_hd, @EnumProc,Longint(Self));<br>&nbsp; if (edit_hd&lt;&gt;0)and(btn_hd&lt;&gt;0) then<br>&nbsp; &nbsp;begin<br>&nbsp; &nbsp;if trim(Ed_time.Text)='' then i:=1<br>&nbsp; &nbsp; else begin<br>&nbsp; &nbsp; &nbsp;try<br>&nbsp; &nbsp; &nbsp; i:=strtoint(Ed_time.Text);<br>&nbsp; &nbsp; &nbsp;except<br>&nbsp; &nbsp; &nbsp; application.MessageBox('输入的时间不是整数!','错误',MB_ICONERROR+MB_OK);<br>&nbsp; &nbsp; &nbsp; exit;<br>&nbsp; &nbsp; &nbsp;end;<br>&nbsp; &nbsp;end;<br>&nbsp; &nbsp; &nbsp;if myqq&lt;&gt;0 then begin<br>&nbsp; &nbsp; &nbsp; &nbsp; application.MessageBox('不想混了呀,作者你也敢骚扰!!!','警告',MB_ICONWARNING+MB_OK);<br>&nbsp; &nbsp; &nbsp; &nbsp; exit;<br>&nbsp; &nbsp; &nbsp;end;<br>&nbsp; &nbsp; &nbsp;Timer1.Interval:=i*1000;<br>&nbsp; &nbsp; &nbsp;Timer1.Enabled:=true;<br>&nbsp; &nbsp; &nbsp;Sbtn_send.Enabled:=false;<br>&nbsp; &nbsp; &nbsp;RB_QQ.Enabled:=false;<br>&nbsp; &nbsp; &nbsp;RB_UC.Enabled:=false;<br>&nbsp; &nbsp; &nbsp;Sbtn_stop.Enabled:=true;<br>&nbsp; &nbsp;end else<br>&nbsp; &nbsp; &nbsp;application.MessageBox('未知错误!','提示',MB_ICONERROR+MB_OK);<br>end;<br><br>procedure TForm1.Ed_timeKeyPress(Sender: TObject; var Key: Char);<br>begin<br>&nbsp; if &nbsp;not(key &nbsp;in ['0'..'9']) then key:=#0;<br>end;<br><br>procedure TForm1.Sbtn_closeClick(Sender: TObject);<br>begin<br>close;<br>end;<br><br>procedure TForm1.Timer1Timer(Sender: TObject);<br>begin<br>&nbsp;sendMessage(edit_hd,WM_SETTEXT,0,Integer(pchar(str_send)));<br>&nbsp;if &nbsp;RB_QQ.Checked then begin<br>&nbsp; &nbsp;sendMessage(edit_hd1,WM_SETTEXT,0,Integer(pchar(str_send)));<br>&nbsp; &nbsp;sendMessage(btn_hd,BM_CLICK,0,0);<br>&nbsp;end else<br>&nbsp; &nbsp;SendMessage(btn_hd,WM_KEYDOWN,VK_RETURN,0);<br>end;<br><br>procedure TForm1.Sbtn_stopClick(Sender: TObject);<br>begin<br>&nbsp; Timer1.Enabled:=false;<br>&nbsp; Sbtn_send.Enabled:=true;<br>&nbsp; Sbtn_stop.Enabled:=false;<br>&nbsp; RB_QQ.Enabled:=true;<br>&nbsp; RB_UC.Enabled:=true;<br>end;<br><br>procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);<br>begin<br>timer1.Enabled:=false;<br>end;<br>function EnumProc1(Hwnd: THandle;lparam: LPARAM): boolean; stdcall;<br>var<br>lpText: Array[0..255] of char;<br>begin<br>Result := true;<br>GetClassName(hwnd,@lpText,255);<br>form1.Memo1.Lines.Add(string(lptext));<br>GetWindowText(HWnd,@lptext,255);<br>form1.Memo1.Lines.Add(string(lptext));<br>end;<br>procedure TForm1.Button1Click(Sender: TObject);<br>var<br>&nbsp; hd:thandle;<br>begin<br>&nbsp;hd:=FindWIndow(nil,'QQ') ;<br>&nbsp; EnumChildWindows(hd, @EnumProc1,Longint(Self));<br>end;<br><br>end.
 
这个初学者态度挺诚恳的,应该帮帮他
 
&nbsp;怎么帮呢?写起来就多了。<br>1:你先找到第一个程序两个编辑框的handle,用枚举函数:enumchildwindow去找。<br>2:分别发送消息sendmessage(编辑框1句柄,wm_settext,128,integer(@abc)),<br>sendmessage(编辑框2句柄,wm_settext,128,integer(@def))<br>3:模拟”确定“按键<br>就说这么多吧。呵呵。。。。
 
多人接受答案了。
 
后退
顶部