S
spdavid
Unregistered / Unconfirmed
GUEST, unregistred user!
我现程序如下但在一步一步调试中正常写入,普通运行状态去无法写入,只能接受回车<br><br>procedure TfrmMain.btn_testClick(Sender: TObject);<br>var<br> hwd: HWND;<br> txt: pchar;<br> i: integer;<br> sSend: String;<br> ch: Byte;<br>begin<br> hwd := FindWindowEx(FindWindow('XLMAIN',nil),0,'EXCEL2',nil);<br> //hwd := FindWindow('Excel',);<br> if hwd = 0 then<br> begin<br> showMessage('EXCEL没打开');<br> exit;<br> end;<br> //写入excel模板文件<br> //文件编号<br> PostMessage(hwd, WM_KEYDOWN, VK_F2, 0);<br><br><br> i := 1;<br> sSend := '中国人1';<br> while i <= Length(sSend) do<br> begin<br> ch := byte(sSend);<br> if Windows.IsDBCSLeadByte(ch) then<br> begin<br> Inc(i);<br> PostMessage(hwd, WM_IME_CHAR, MakeWord(byte(sSend), ch), 0);<br> end<br> else<br> PostMessage(hwd, WM_IME_CHAR, word(ch), 0);<br> Inc(i);<br> end;<br><br> PostMessage(hwd, WM_KEYDOWN, VK_RETURN, 0);<br> PostMessage(hwd, WM_KEYDOWN, VK_TAB, 0);<br>end;