Custom Tooltip Formatting

2019-08-20 08:08发布

问题:

I am working in plain old native C on Windows. No other platforms, no C++. (Yes, I'm a dinosaur.)

I am trying to find an example of what I think of as an "owner draw tooltip control" but that does not appear to exist. At least not for the standard Windows tooltip control. I have tried to search for a library or source that implements a custom tooltip control, but all I can find is things that extend controls in .NET (or in other environments that are not where I am working.)

My hope is to support markdown (or something like it) for the text in the tooltip window. Mostly, I want to clearly differentiate the title from the content, and have some limited formatting of the content (bold, italics, color, and columns, mostly.)

I don't expect a full solution here, I am just hoping that someone else has already found a solution and can point me to where they found it. Please?

回答1:

Tooltips cannot be owner drawn, but they can be "custom drawn".

Custom drawn Win32 controls allow you to override the built-in drawing by receiving and responding to the NM_CUSTOMDRAW notification. You can read about custom draw here.

You can refer to the specific documentation on the tooltip control, see:

NM_CUSTOMDRAW (tooltip) notification code

Finally, here is a good tutorial demonstrating the whole thing in C.