怎么用sendmessage向excel程序发送中文字(200分)

  • 主题发起人 主题发起人 spdavid
  • 开始时间 开始时间
S

spdavid

Unregistered / Unconfirmed
GUEST, unregistred user!
我现程序如下但在一步一步调试中正常写入,普通运行状态去无法写入,只能接受回车<br><br>procedure TfrmMain.btn_testClick(Sender: TObject);<br>var<br>&nbsp; hwd: HWND;<br>&nbsp; txt: pchar;<br>&nbsp; i: integer;<br>&nbsp; sSend: String;<br>&nbsp; ch: Byte;<br>begin<br>&nbsp; hwd := FindWindowEx(FindWindow('XLMAIN',nil),0,'EXCEL2',nil);<br>&nbsp; //hwd := FindWindow('Excel',);<br>&nbsp; if hwd = 0 then<br>&nbsp; begin<br>&nbsp; &nbsp; &nbsp; showMessage('EXCEL没打开');<br>&nbsp; &nbsp; &nbsp; exit;<br>&nbsp; end;<br>&nbsp; //写入excel模板文件<br>&nbsp; //文件编号<br>&nbsp; PostMessage(hwd, WM_KEYDOWN, VK_F2, 0);<br><br><br>&nbsp; i := 1;<br>&nbsp; sSend := '中国人1';<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; PostMessage(hwd, WM_IME_CHAR, MakeWord(byte(sSend), ch), 0);<br>&nbsp; &nbsp; end<br>&nbsp; &nbsp; else<br>&nbsp; &nbsp; PostMessage(hwd, WM_IME_CHAR, word(ch), 0);<br>&nbsp; Inc(i);<br>&nbsp; end;<br><br>&nbsp; PostMessage(hwd, WM_KEYDOWN, VK_RETURN, 0);<br>&nbsp; PostMessage(hwd, WM_KEYDOWN, VK_TAB, 0);<br>end;
 
SendMessage(句柄, WM_SETTEXT, 0, Integer(PChar(要发送的文字)));
 
和我上面所说的一样调试的时候没事,实际运行就出问题
 
同意Kgafly
 
后退
顶部