2

I need to create a custom hint window (with it's own color and layout) for a specific control (not the entire application)

The hint text itself will not be connected to that specific Hint property control.

As suggested I wrote a handler for CM_HINTSHOW (This worked if the Control has ShowHint=True):

procedure TMyControl.CMHintShow(var Message: TMessage);
begin
  Form1.caption := 'x';
  // Here I will display my own Hint window 
  // inherited;
end;

But now, how do I know when/where to hide it when the hint times out? neither CM_HINTSHOW or CM_HINTSHOWPAUSE gives me this info.

zig
  • 4,524
  • 1
  • 24
  • 68

1 Answers1

6

In your CM_HINTSHOW message handler, you can cast the lParam value to a PHintInfo pointer and then customize its fields as needed. For instance, to simply change the background color, set the THintInfo.HintColor field. To change the layout of the hint, you can derive a new class from THintWindow and assign that class type to the THintInfo.HintWindowClass field.

Let the VCL manage the hint for you, including showing and hiding it.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • I need to show Unicode text on the new Hint Window + Image. I don't think I can simply derive a class `THintWindow` because the `ActivateHint` excepts `AHint: String` (AnsiString) – zig Nov 10 '14 at 17:25
  • The VCL calls `THintWindow.ActivateHintData()` when activating a hint, so you can use the `THintInfo.HintData` field to pass custom data to the hint, such as your Unicode text. – Remy Lebeau Nov 10 '14 at 17:38
  • Seem this is the right way. Can I assigned anything to back to `HintData`? – zig Nov 10 '14 at 17:38
  • Yes, it is just a raw `Pointer` that is passed as-is, so you can assign whatever you want to it. – Remy Lebeau Nov 10 '14 at 17:39
  • Will i also need to keep a reference to that Data in the `TMyHintWindow` if I later want to use it in `TMyHintWindow.Paint` for example? Also, should I return `Message.Result := 1` and `inherited'? – zig Nov 10 '14 at 17:55
  • 1
    @zig: Yes, you will have to keep a reference to the data if you need to continue accessing it after `ActivateHintData()` has exited. Returning any value *other than* 0 for `CM_HINTSHOW` will cancel the hint. If you call `inherited`, that gives the base control code a chance to accept/reject/customize the hint, such as formatting the `HintStr` when a `TAction` is assigned to the control. So you could call `inherited` first, and then do your customizations if `Message.Result` is still 0. – Remy Lebeau Nov 11 '14 at 17:02