如何向一个外部程序输入中文字符串,此外部程序有多个Edit。谁有经验? (100分)

我帮忙UP一下。
 
在向其他程序窗口中某一个控件里发送文本时,我做了这么一个函数,<br>但执行时连窗口都找不到,大家看看,想想办法。<br><br><br>function ShowChildWinID( WinCaption:string; CtrlClass:string ):boolean;<br>var<br>&nbsp; cnt: integer;<br><br>&nbsp; function EnumChildProc(Hwnd:THandle;lParam:LParam):boolean;<br>&nbsp; var<br>&nbsp; &nbsp; WindowCaption,WindowClass:array[0..254] of Char;<br>&nbsp; begin<br>&nbsp; &nbsp; GetClassName(Hwnd,WindowClass,255);<br>&nbsp; &nbsp; if Pos('CtrlClass',UpperCase(StrPas(WindowClass))) &gt; 0 then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; Inc(cnt);<br>&nbsp; &nbsp; &nbsp; SendMessage(Hwnd,WM_SETTEXT,0,LongInt(PChar(IntToStr(cnt))));<br>&nbsp; &nbsp; &nbsp; //if cnt = ChildWinID then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;这里是为了向固定的ChildWinID显示S &nbsp; &nbsp; &nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; //SendMessage(Hwnd,WM_SETTEXT,0,LongInt(PChar(s)));<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; Result := True;<br>&nbsp; end;<br><br>&nbsp; function EnumWindowsProc(Hwnd:THandle;lParam:LParam):boolean;<br>&nbsp; var<br>&nbsp; &nbsp; WindowCaption:array[0..254] of Char;<br>&nbsp; &nbsp; WinCapStr:string;<br>&nbsp; begin<br>&nbsp; &nbsp; GetWindowText(Hwnd,WindowCaption,255);<br>&nbsp; &nbsp; if StrPas(WindowCaption)= WinCaption then<br>&nbsp; &nbsp; WinCapStr := StrPas(WindowCaption);<br>&nbsp; &nbsp; if WinCapStr = WinCaption then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; cnt := 0;<br>&nbsp; &nbsp; &nbsp; EnumChildWindows(Hwnd,@EnumChildProc,0);<br>&nbsp; &nbsp; &nbsp; Result := False;<br>&nbsp; &nbsp; &nbsp; Exit;<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; Result := True;<br>&nbsp; end;<br><br>begin<br>&nbsp; Enumwindows(@EnumWindowsProc,0);<br>end;<br><br>///////////////////////////////////////////////////////////////////////////<br>调用方法<br>procedure TForm1.Button2Click(Sender: TObject);<br>begin<br>&nbsp; ShowChildWinID('FormCustom','Edit');<br>end;
 
[?][?][?]<br>相同的问题?<br>http://www.delphibbs.com/delphibbs/DispQ.asp?LID=1395209
 
我想要在Sendkeys中,先选中文本,后发送字符串,但有点问题。<br><br><br>procedure Sendkeys(focushld: HWND; sSend: string);<br>var<br>&nbsp; i:integer;<br>&nbsp; ch: byte;<br>begin<br>&nbsp; i := 1;<br><br>&nbsp; SendMessage(focushld, WM_IME_SELECT, WPARAM(true), 255); &nbsp; <br>&nbsp;// 要选中文本,但这处没有选中。<br><br>&nbsp; while i &lt;= Length(sSend) do<br>&nbsp; begin<br>&nbsp; &nbsp; ch := byte(sSend);<br>&nbsp; &nbsp; if Windows.IsDBCSLeadByte(ch) then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; Inc(i);<br>&nbsp; &nbsp; &nbsp; SendMessage(focushld, WM_IME_CHAR, MakeWord(byte(sSend), ch), 0);<br>&nbsp; &nbsp; end<br>&nbsp; &nbsp; else<br>&nbsp; &nbsp; SendMessage(focushld, WM_IME_CHAR, word(ch), 0);<br>&nbsp; Inc(i);<br>&nbsp; end;<br>end;
 
接受答案了.
 
顶部