winapi - 以编程方式写入丰富编辑后,EM_UNDO 不起作用

标签 winapi sendmessage c++builder-10-seattle

在 Win7-64 上使用 C++ Builder 10 Seattle。

我有一个 TRichEdit 控件,可以通过按钮单击事件向其中写入内容:

MyRichEdit->SelText = t_string;

我希望能够撤消该更改,因此我有一个带有快捷键 Ctrl+Z 的菜单项可以执行以下操作:

SendMessage(MyRichEdit->Handle, EM_UNDO, 0, 0);

如果我在丰富的编辑中键入,则“撤消”将按预期工作,但不会撤消以编程方式分配的“粘贴”。

我在一个使用 Borland C++ Builder v6 构建的旧应用程序中有类似的代码,并且它可以在那里工作。

我的问题是:上面的代码应该撤消 write-to-SelText 操作吗?或者我还需要做些什么吗?

最佳答案

SelText setter 的实现如下所示:

procedure TCustomEdit.SetSelText(const Value: string);
begin
  SendTextMessage(Handle, EM_REPLACESEL, 0, Value);
end;

EM_REPLACESEL 的文档说:

Parameters

wParam

Specifies whether the replacement operation can be undone. If this is TRUE, the operation can be undone. If this is FALSE , the operation cannot be undone.

lParam

A pointer to a null-terminated string containing the replacement text.

VCL 正在发送 0,其值为 FALSE,因此操作无法撤消。您需要避免使用 SelText,而是直接发送 EM_REPLACESEL,并将 TRUE 作为 wParam 传递。

我检查了 Delphi 6 VCL 的源代码,在发送此消息时,它也总是为 wParam 传递 0,因此我期望旧版本的VCL 的行为方式相同。尽管如此,您现在知道如何解决该问题了。

顺便说一句,您可以通过调用 MyRichEdit->Undo() 来替换发送 EM_UNDO ,它的作用完全相同。

关于winapi - 以编程方式写入丰富编辑后,EM_UNDO 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35367873/

相关文章:

c++ - 当电源从 AC 切换到 DC 并返回时通知?

exception - Grails中的JMS MessageCreator.createMessage()

c++ - TGridOptions 上二进制表达式的无效操作数

c++ - 使用Firedac进行MongoDB的时间范围查询

c# - 为什么 DwmGetWindowAttribute 与 DWMWA_EXTENDED_FRAME_BOUNDS 在切换监视器时表现异常?

visual-studio - 将代码从 Visual Studio 6 移植到 Visual Studio 2013 后对话框边框不同

c# - 如何让两个应用程序通过 LAN 找到并连接?

javascript - 在 Chrome 扩展中使用 sendMessage 时 webkitMediaStream 对象类型丢失

c - 如何协调被 Getasynckeystate 阻止的 Sendmessage、SendInput、Mouse_event?