rommmcek,
Thank you for your contribution. I tested it and both of the examples work great! I have a few notes. I hope you don't mind.
1) The function creates a logical font but there is no mechanism for deleting the font. Fixing this is only needed for completeness. The amount of memory saved is trivial.
This is an easy fix. Simply have the function return the handle to the font that was created (Ex:
Return hFont) and then delete the font after the tooltip is destroyed. For example:
Code: Select all
Tooltip Brown Chicken`, Brown Cow
hTTFont:=ToolTipFnt()
MsgBox The tooltip will continue to show while this window is open.
Tooltip ;-- Destroy the tooltip
Fnt_DeleteFont(hTTFont) ;-- Delete the tooltip font
2) Calling the function multiple times for the same AutoHotkey tooltip is not a good idea because a new font is created for every call and the previous font (if any) is not destroyed. This will create the equivalent of a memory leak that will use a tiny bit of additional memory every time the function is called. Probably not enough to worry about for the average script but the extra memory usage can add up for a long-running script.
One possible fix is to delete the previous font before creating a new one (see #1) but the better and more efficient solution is to only call the function once for every tooltip. Let me explain...
When a tooltip is created for the first time, AutoHotkey will create a new tooltip control. That control is destroyed when the Tooltip command is called without any parameters. For example:
Code: Select all
Tooltip Brown Chicken ;-- New tooltip control is created
Sleep 2000
Tooltip ;-- Tooltip control is destroyed
However, if a tooltip exists and the Tooltip command is called again, a new tooltip control is not created. Instead, the tooltip control is updated with the new text from the Tooltip command. Since a new tooltip control is not created, the font changes made by the function remain in effect. For example:
Code: Select all
Tooltip Brown Chicken ;-- New tooltip control is created
hTTFont:=ToolTipFnt() ;-- New tooltip font is set
Sleep 2000
Tooltip Brown Cow ;-- The same tooltip control is used
;-- No need to set/update the font here
Sleep 2000
Tooltip ;-- Tooltip control is destroyed
Fnt_DeleteFont(hTTFont)
3) In your example, you imply that the function somehow fixes a tooltip positioning bug when the pointer and the tooltip is moved to the bottom right section of the screen. The positioning code for the AutoHotkey tooltip has been in AutoHotkey since as long as I can remember and changing the font or font size doesn't (or shouldn't) change how it works. OTOH, I'm not experiencing the "skip to the top" problem you mentioned and I don't have Windows 10 to try to duplicate the problem.
Once again, thank you for your contribution.