delphi - delphi中拦截hint事件

标签 delphi delphi-xe2 windows-messages hint

我正在尝试在组件内部的运行时临时更改提示文本, 无需更改 Hint 属性本身。

我 try catch CM_SHOWHINT,但此事件似乎只出现在 表单,但不是组件本身。

插入 CustomHint 也不起作用,因为它需要文本 来自 Hint 属性。

我的组件是 TCustomPanel 的后代

这就是我正在尝试做的事情:

procedure TImageBtn.WndProc(var Message: TMessage);
begin
  if (Message.Msg = CM_HINTSHOW) then
    PHintInfo(Message.LParam)^.HintStr := 'CustomHint';
end;

我在互联网上的某个地方找到了这段代码,不幸的是它不起作用。

最佳答案

CM_HINTSHOW 确实正是您所需要的。这是一个简单的例子:

type
  TButton = class(Vcl.StdCtrls.TButton)
  protected
    procedure CMHintShow(var Message: TCMHintShow); message CM_HINTSHOW;
  end;

  TMyForm = class(TForm)
    Button1: TButton;
  end;

....

procedure TButton.CMHintShow(var Message: TCMHintShow);
begin
  inherited;
  if Message.HintInfo.HintControl=Self then
    Message.HintInfo.HintStr := 'my custom hint';
end;

问题中的代码无法调用inherited,这可能就是它失败的原因。或者,类声明可能省略了 WndProc 上的 override 指令。无论如何,我在这个答案中的方式更清晰。

关于delphi - delphi中拦截hint事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12838372/

相关文章:

delphi - Delphi 的虚拟 TreeView 中的快速滚动

delphi - 在 Delphi 中显示资源管理器菜单

delphi - Delphi Firemonkey中的鼠标事件动画

Delphi XE2 EnumWindows 无法正常工作

macos - 如何在 Firemonkey 中创建 "No Activate"表单

autohotkey - 这个 AHK 脚本如何工作?

delphi - 为什么编译器会说 "statement expected, but expression of type ' <x >' found"?

forms - Delphi中如何访问父窗体

windows - 如何捕获从此菜单发送的 Windows 消息?

c++ - 无法接收/捕获 Windows 消息