向命令行窗口发送中文的问题,出现乱码!

maysoft 2014-09-29 08:07:28

procedure SendMessageToCMD(hwd:HWND; str:string);
var
i:integer;
begin
i:=1;
while i<=length(str)do
begin
if IsDBCSLeadByte(byte(str[i])) then
begin
inc(i);
SendMessage(hwd, WM_IME_CHAR, MakeWord(byte(str[i]), byte(str[i-1])), 0);
end else
begin
sendmessage(hwd,WM_IME_CHAR,word(byte(str[i])),0) ;
inc(i);
end;
end;
end;


我用上面的方法去想命令行窗口发送字符串,中文就是乱码,有没有办法解决?
...全文
550 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
frtrnr 2014-09-30
  • 打赏
  • 举报
回复
大富翁论坛 -> newnob (2002-11-03 15:16:00) procedure SendMessageToCMD(focushld: HWND; sSend: string); var i:integer; ch: byte; begin i := 1; SendMessage(focushld, WM_IME_SELECT, WPARAM(true), 255); // 要选中文本,但这处没有选中。 while i <= Length(sSend) do begin ch := byte(sSend[i]); if Windows.IsDBCSLeadByte(ch) then begin Inc(i); SendMessage(focushld, WM_IME_CHAR, MakeWord(byte(sSend[i]), ch), 0); end else SendMessage(focushld, WM_IME_CHAR, word(ch), 0); Inc(i); end; end;
maysoft 2014-09-29
  • 打赏
  • 举报
回复
引用 1 楼 s11ss 的回复:
SendMessage(hwd, WM_IME_CHAR, MakeWord(byte(str[i]), byte(str[i-1])), 0); 这句下边加一句inc(i)
仍然是乱码
s11ss 2014-09-29
  • 打赏
  • 举报
回复
SendMessage(hwd, WM_IME_CHAR, MakeWord(byte(str[i]), byte(str[i-1])), 0); 这句下边加一句inc(i)

1,183

社区成员

发帖
与我相关
我的任务
社区描述
Delphi Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧