分析了一下,可能找到的是显示信息的窗口句柄,没找到回复消息的窗口句柄.<br>我用CAkk以前的一段代码解决的.<br>代码如下<br>procedure SendKeys(Mstr:string);<br>var CharCode,i:integer;<br> Sstr:string;<br> focushld,windowhld:hwnd;<br> threadld:dword;<br>begin<br> windowhld:=GetForegroundWindow;<br> threadld:=GetWindowThreadProcessId(Windowhld,nil);<br> AttachThreadInput(GetCurrentThreadId,threadld,true);<br> Focushld:=getfocus;<br> AttachThreadInput(GetCurrentThreadId,threadld,false);<br> if focushld<>0 then<br> begin<br> for i:=1 to length(Mstr) do<br> begin<br> Sstr:=Mstr;<br> CharCode:=ord(Sstr[1]);<br> if length(Sstr)>1 then<br> CharCode:=CharCode shl 8+ord(Sstr[2]);<br> sendmessage(Focushld,WM_IME_CHAR,CharCode,1);<br> end;<br> end;<br>end;<br><br><br>然后sendkey('字符串');<br><br><br>找到窗口句柄代码如下:<br>procedure TForm1.Button1Click(Sender: TObject);<br>var hparent,hbutton:hwnd;//定义句柄变量<br>begin<br> hparent:=findwindow(nil,'对话模式');//得到窗口句柄<br> hbutton:=findwindowex(hparent,0,nil,'送讯息(&S)');//得到窗体的按钮句柄<br> if (hparent=0) or (hbutton=0)<br> then<br> MessageBox(Handle,' 没有找到句柄',' 错误', MB_ICONWARNING)<br> else<br> begin<br> showmessage('窗体句柄'+inttostr(hpaarent)+'按钮句柄'+inttostr(hbutton));<br> end;<br>end;