使用 Win API 将文本附加到备忘录 [英] Append text to memo using Win API

查看:44
本文介绍了使用 Win API 将文本附加到备忘录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用此代码附加文本行

I'm trying to append text lines with this code

SendMessage(Form1.log.Handle, WM_SETTEXT, 0, Integer(PChar(textLog)));

//textLog 是一些行,例如程序开始于 xxx"等

// textLog are some lines eg 'Program started at xxx' etc

但它不会追加,只是设置新文本

but it doesnt append, just set new text

推荐答案

找到完整的解决方案

    procedure appendLog(const S: string);
var
  SelStart, LineLen: Integer;
  Line: string;
begin

  SelStart := SendMessage(Form1.log.Handle, EM_LINEINDEX, 0, 0);
  if SelStart >= 0 then Line := S + #13#10 else
    begin
      SelStart := SendMessage(Form1.log.Handle, EM_LINEINDEX, -1, 0);
      if SelStart < 0 then Exit;
      LineLen := SendMessage(Form1.log.Handle, EM_LINELENGTH, SelStart, 0);
      if LineLen = 0 then Exit;
      Inc(SelStart, LineLen);
      Line := #13#10 + s;
    end;

  SendMessage(Form1.log.Handle, EM_SETSEL, SelStart, SelStart);
  SendMessage(Form1.log.Handle, EM_REPLACESEL, 0, Longint(PChar(Line)));

end;

这篇关于使用 Win API 将文本附加到备忘录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆