ToolTipFont / ToolTipColor - options for the ToolTip command

Post your working scripts, libraries and tools
lexikos
Posts: 5938
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

ToolTipFont / ToolTipColor - options for the ToolTip command

05 Oct 2014, 00:47

ToolTipFont(Options, Name)
Sets the font options and name for subsequent calls to the ToolTip command.
Parameters are the same as for Gui Font.
Pass "Default" for Options to restore the font setting to default.

ToolTipColor(Background, Text)
Sets the background and text colours for subsequent calls to the ToolTip command.
Parameters are the same as for Gui Color.
Pass "Default" for either parameter to restore it to its default. If both are default, the system visual style is used.

Code: [Select all] [Expand] [Download] (ToolTipOpt.ahk)GeSHi © Codebox Plus



Example

Code: [Select all] [Download] GeSHi © Codebox Plus

ToolTip Standard tooltip
Sleep 1000
ToolTipFont("s20", "Comic Sans MS")
ToolTip ToolTip with custom font
Sleep 1000
ToolTipColor("Black", "White")
ToolTip ToolTip with custom font and color
Sleep 1000
ExitApp

About
While testing just me's ToolTipEx and writing my own GUI-based version, I realized that it's not necessary to reimplement the command just to stylize a tooltip. This script uses a message hook to modify the tooltip when AutoHotkey sends it an update message (TTM_UPDATETIPTEXT). It uses the following tricks:

  • Use a CallWndProc hook to intercept messages sent to tooltip windows owned by by the script. It would be better to subclass the tooltips_class32 window class (within the current process), but that requires creating a tooltips_class32 window for use with GetClassLong/SetClassLong.

    Caution: Hooking messages which can interrupt AutoHotkey's commands may cause the command's parameters to be overwritten. The hook callback must avoid certain operations that use the "deref buffer", such as concatenation (except when the result is directly assigned to a variable) or functions returning strings, including WinExist (which returns a hexadecimal string).

  • Use a hidden GUI to parse font options/names and colour values/names.
  • Apply the WS_CHILD style to a GUI so that DetectHiddenWindows isn't needed.

Notes:
  • It's possible to embed a GUI into a tooltip window.
  • It's possible to resize a tooltip window from within the message hook, but you must WinSet Region to clear the tooltip's shape first.
Last edited by lexikos on 06 Jul 2016, 03:51, edited 3 times in total.
Skrell
Posts: 163
Joined: 23 Jan 2014, 12:05

Re: ToolTipFont / ToolTipColor - options for the ToolTip com

05 Oct 2014, 13:17

can this be used to hook all windows displayed tooltips and change their appearance? Or is this ONLY for modifying autohotkey generated tooltips?
User avatar
joedf
Posts: 6286
Joined: 29 Sep 2013, 17:08
Facebook: J0EDF
Google: +joedf
GitHub: joedf
Location: Canada, Quebec
Contact:

Re: ToolTipFont / ToolTipColor - options for the ToolTip com

05 Oct 2014, 13:17

Very nice :)
just me
Posts: 5397
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: ToolTipFont / ToolTipColor - options for the ToolTip com

06 Oct 2014, 00:44

nice (nice trick also: SendMessage 0x138, hdc, htext,, ahk_id %hgui%),
but how to switch back to the default font and colors?
lexikos
Posts: 5938
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: ToolTipFont / ToolTipColor - options for the ToolTip com

06 Oct 2014, 01:10

Skrell wrote:can this be used to hook all windows displayed tooltips and change their appearance? Or is this ONLY for modifying autohotkey generated tooltips?
Refer to my first post. I'll let you infer your own answers.

just me wrote:but how to switch back to the default font and colors?
Reload ;)

It's just a matter of clearing the static variables and either creating a new window or resetting the window theme. I've updated the script so that it does this if you pass "Default" for the parameter(s).
User avatar
Relayer
Posts: 112
Joined: 30 Sep 2013, 13:09
Location: Delaware, USA

Re: ToolTipFont / ToolTipColor - options for the ToolTip com

06 Oct 2014, 12:37

For some reason I get the plain old TT while running the example. I'm using AutoHotkey v1.1.14.04

Relayer
guest3456
Posts: 2313
Joined: 09 Oct 2013, 10:31

Re: ToolTipFont / ToolTipColor - options for the ToolTip com

06 Oct 2014, 12:41

Relayer wrote:For some reason I get the plain old TT while running the example. I'm using AutoHotkey v1.1.14.04

Relayer


Maybe its for AHK v2, since the default function parameter values are assigned with :=. Try replacing those with =

lexikos
Posts: 5938
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: ToolTipFont / ToolTipColor - options for the ToolTip com

08 Oct 2014, 01:33

No, it is not compatible with v2. It was also not ANSI compatible, but it is now (v1.002). It already worked with v1.1.14.04 Unicode.

By the way, there have been numerous bug fixes and a few new features added since v1.1.14.04...

Optional parameters have supported := since v1.1.09.
User avatar
Relayer
Posts: 112
Joined: 30 Sep 2013, 13:09
Location: Delaware, USA

Re: ToolTipFont / ToolTipColor - options for the ToolTip com

09 Oct 2014, 08:32

Thank you lexikos!

You have my utmost respect. What you've done with AutoHotKey has been truly amazing and has enabled me to be so much more productive and have way more fun than I could have without your work. I can only hope you maintain your energy to stick with it.

Relayer
freiheitner
Posts: 4
Joined: 13 Oct 2014, 19:54

Re: ToolTipFont / ToolTipColor - options for the ToolTip com

16 Oct 2014, 22:29

Seriously cool. I've been searching for a fairly simple way to do this since default tooltips on Windows 7 are pretty un-attention-grabbing. Thanks for this!
slur
Posts: 10
Joined: 13 Jun 2014, 07:05

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

21 Oct 2015, 05:35

I don't know this is just me or not

but this code gives me funny results

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus


except the first one, which says Hello as expected,
others give me ahk_class tooltips_class32 ahk_id __random_id_here__

WindowsXP SP3 AHK1.1.22.07 U32
User avatar
boiler
Posts: 2370
Joined: 21 Dec 2014, 02:44

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

21 Oct 2015, 11:13

This is very useful. Thanks for providing it.
GS SAHU
Posts: 35
Joined: 29 Sep 2014, 12:18

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

24 Oct 2015, 08:25

idea!

i things tooltip showing in callouts( as cloud,oval, rectangular, rounded rectangualar callouts) with a cartoon image like saying tooltip text.text speak in sound also a other option in tooltip.

like: :offtopic:

it is possible?
User avatar
joedf
Posts: 6286
Joined: 29 Sep 2013, 17:08
Facebook: J0EDF
Google: +joedf
GitHub: joedf
Location: Canada, Quebec
Contact:

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

24 Oct 2015, 12:37

Try gDip ?
User avatar
Avi
Posts: 193
Joined: 30 Sep 2013, 09:51
Facebook: avi.aryan.ap
Google: +AviAryan
GitHub: aviaryan
Location: India
Contact:

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

08 Dec 2015, 11:48

I notice that when a custom font tooltip is active (visible), hotkeys get suspended. For example, in the following code pressing Win+O will not close the script when ToolTipFont is set. But when you comment that line, the hotkey works.

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus



I tried commenting Critical 999 in _TTWndProc and that did work to some extent but it had other weird bugs (in some other script).

Using AHK 1.1.22.07 U32 on Win 8.1 x64

EDIT - I tried the same thing with justme's TooltipEx and that worked.
Clipjump Clipboard Manager : More Scripts

Image
lexikos
Posts: 5938
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

09 Dec 2015, 02:01

Try one of:
1. Remove , "F", otherwise Critical 999 will affect whatever thread was active when the hook was called.
2. Use Critical Off before returning from _TTWndProc. (Instead of "Off", you may use the value A_IsCritical had before Critical 999 was called.)
lexikos
Posts: 5938
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

06 Jul 2016, 03:53

I've updated the script with workarounds for slur's issue (also reported recently by Lampshade).
arcticir
Posts: 494
Joined: 17 Nov 2013, 11:32

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

06 Jul 2016, 07:42

Hi,We can limit the width of it?
rommmcek
Posts: 349
Joined: 15 Aug 2014, 15:18

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

06 Jul 2016, 09:05

@arcticir: Good question!
Btw, wouldn't be nice to have an option for getting dimensions of ToolTip? OS is obviously aware of them for ToolTipFont behaves exactly the same as native ToolTip, especially in right bottom corner of the screen.
Now I use ToolTipColor as:

Code: [Select all] [Download] GeSHi © Codebox Plus

TooTipColor("WhatEverExceptDefault", "BackgroundColor")
Text Color doesn't work.
Edit: That was a lightning fast fix! So text color problems are history!

But I noticed another "limitation" (it was happening in 1.003 too - in earlier versions dunno, 'couse I didn't use them): In quick consecutive changes of the ToolTip once being modified by ToolTipFont sometimes happens (not very often), broken display of the ToolTip, see pic.
Attachments
ToolTipFont.jpg
Last edited by rommmcek on 07 Jul 2016, 01:35, edited 1 time in total.

Return to “Scripts and Functions”

Who is online

Users browsing this forum: sbrockle and 13 guests