ToolTipFont / ToolTipColor - options for the ToolTip command

Post your working scripts, libraries and tools for AHK v1.1 and older
knightrule
Posts: 6
Joined: 24 May 2021, 02:23

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

17 Jan 2023, 22:33

ntepa wrote:
16 Jan 2023, 19:20

Code: Select all

#SingleInstance Force
CoordMode, ToolTip, Screen
ToolTipFont("s14", "Comic Sans MS") 
ToolTipColor("8080", "white")
ToolTip, This is a ToolTip with custom font and color, 0, 0
return

It looks like this in Windows 11:

tooltip.png

You need a decoy tooltip line like this, after the Coordmode line.

Code: Select all

CoordMode, ToolTip, Screen
tooltip .							; a decoy tooltip, any text will do, the period is to make it small
ToolTipFont("s14", "Comic Sans MS") 
ToolTipColor("8080", "white")
ToolTip, This is a ToolTip with custom font and color, 0, 0
return
Correction with my first post:

Code: Select all

" if !initialize {			; You need to a decoy tooltip each time tooltip have been cleared. 
	initialize:= 1 "		; if it has not been cleared then you can use TooltipColor just like normal tooltip.

ToolTip_Color_Green()  			; this is how i use it, just 2 lines, it include SetTimer, Tooltip_Remove, -1500
tooltip Test - this is green		; which can be overide with a new settimer
Last edited by gregster on 17 Jan 2023, 22:38, edited 2 times in total.
Reason: Pulled text from codebox.
knightrule
Posts: 6
Joined: 24 May 2021, 02:23

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

20 Jan 2023, 09:46

Code: Select all

MouseGetPos x, y 
tooltip .,,,2
tooltip .,,,3
tooltip .,,,4
tooltip .,,,5
tooltip .,,,6
tooltip .,,,7 
tooltip .,,,8 
tooltip .,,,9 
tooltip .,,,10
tooltip .,,,11
tooltip .,,,12
tooltip .,,,13
tooltip .,,,14
tooltip .,,,15
tooltip .,,,16
tooltip .,,,17
; tooltip .,,,18
tooltip .,,,19
tooltip .,,,20
ToolTip_Color_Red() 
tooltip % "   testing color red  ",x,y,20
ToolTip_Color_Red1() 
tooltip % "   testing color red1  ",x,y+20,2
ToolTip_Color_Red2() 
tooltip % "   testing color red2  ",x,y+40,3
ToolTip_Color_Yellow() 
tooltip % "   testing color yellow  ",x,y+60,4
ToolTip_Color_Yellow1() 
tooltip % "   testing color yellow1  ",x,y+80,5
ToolTip_Color_Orange() 
tooltip % "   testing color orange  ",x,y+100,6
ToolTip_Color_Orange1() 
tooltip % "   testing color orange1  ",x,y+120,7
ToolTip_Color_Lime() 
tooltip % "   testing color lime  ",x,y+140,8
ToolTip_Color_Green01() 
tooltip % "   testing color green01  ",x,y+160,9
ToolTip_Color_Green() 
tooltip % "   testing color green  ",x,y+180,10
ToolTip_Color_Blue02() 
tooltip % "   testing color blue02  ",x,y+200,11
ToolTip_Color_Blue01() 
tooltip % "   testing color blue01  ",x,y+220,12
ToolTip_Color_Blue() 
tooltip % "   testing color blue  ",x,y+240,13
ToolTip_Color_Cyan() 
tooltip % "   testing color cyan  ",x,y+260,14
ToolTip_Color_Pink() 
tooltip % "   testing color pink  ",x,y+280,15
ToolTip_Color_Lavender() 
tooltip % "   testing color lavender  ",x,y+300,16
ToolTip_Color_Purple()
tooltip % "   testing color purple  ",x,y+320,17
ToolTip_Color_Brown01() 
tooltip % "   testing color brown - no decoy ",x,y+340,18
ToolTip_Color_Brown() 
tooltip % "   testing color brown  ",x,y+360,19
return

ToolTip_Color_Lime() {		; sample
	Global
	tt_size:="s12", tt_font:="Calibri", tt_text:=brown, tt_background:=lime 
	ToolTip_Color()
}
Attachments
Clip ToolTip_Color().png
Clip ToolTip_Color().png (17.11 KiB) Viewed 2630 times
LAPIII
Posts: 668
Joined: 01 Aug 2021, 06:01

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

20 Jan 2023, 12:10

@knightrule I copied and pasted your last script into SciTE4AutoHotkey and got:

TEST.ahk 20_01_23 12⦂10⦂46⦂085 PM.jpg
TEST.ahk 20_01_23 12⦂10⦂46⦂085 PM.jpg (38.38 KiB) Viewed 2611 times

Am I missing something?
User avatar
boiler
Posts: 16981
Joined: 21 Dec 2014, 02:44

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

20 Jan 2023, 13:17

@LAPIII -- See the following where it says "sample"?

Code: Select all

ToolTip_Color_Lime() {		; sample
	Global
	tt_size:="s12", tt_font:="Calibri", tt_text:=brown, tt_background:=lime 
	ToolTip_Color()
}

By now, when you get an error saying there is a call to a nonexistent function, you should know that it's missing the function. You would need to provide a function with the details for each. It could have been done more efficiently than a separate function for each one, but that's what was chosen, so write an equivalent function for whichever one(s) you want to use yourself. Or write a function where you can pass the color to it, which is a much better approach.
knightrule
Posts: 6
Joined: 24 May 2021, 02:23

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

20 Jan 2023, 13:48

LAPIII wrote:
20 Jan 2023, 12:10
@knightrule I copied and pasted your last script into SciTE4AutoHotkey and got:

Am I missing something?
1. need the full code from ToolTipOpt v1.004, which i did not repost.
2. copy/mod my Function, or you can use it without any function.
3. You should test ToolTipOpt before it was broken, by downgrading AHK to 1.1.33.11.
4. Once you already know how to use ToolTipOpt and you don't want to downgrade then use the work around: "tooltip ." until someone who understand the code can fix it.

Code: Select all

tooltip .		; this line is only for AHK 1.1.34 to current, you might be able this move this offscreen, i had no need to tested it, as this already works fine for me.
ToolTipFont("s20", "Comic Sans MS")
ToolTipColor("Black", "Red")
ToolTip testing testing testing
Some color natively recognize by ToolTipColor:
Black, White, Blue, Red, Green, Yellow, Purple, Gray, magenta, cyan, brown

Or you can use a freeware called ColorMania 12.1 to pick out HTML Hex, it has vast color library, under Name, Sort by Hue.
Use it like this:

Code: Select all

	ToolTipColor("Black", "87CEFA")		; notice black is in " quotes "
		; or
	SkyBlue:="87CEFA", Black:= "black"  
	ToolTipColor(Black, SkyBlue)			; now without quotes as it's a variable
My updated function:

Code: Select all

;~~--------- This line is my code folding for Notepad++ ------------------------------------
ToolTip_Color() {
	Global
	if !cyan {	;; HTML Hex Colors, sort by group, light at top. Choosen from ColorMania
		red    		:="FF0000"
		r_230		:="E60000"   	;; Electric
		r_204		:="CC0000"		;; Boston University	
		r_Firebrick	:="B22222"
		r_144		:="900000" 		;; Crimson

		yellow		:="FEDF00"		;; Pantone
		y_Jonquil	:="F4CA16"
		orange		:="FFA500"
		o_Dark		:="FF8C00"
		o_Tangelo	:="F07427"

		lime		:="BFFF00"
		g_yellow	:="9ACD32"
		g_Kelly		:="4CBB17"
		g_y_wheel	:="30B21A"
		green		:="008000"

		SkyBlue		:="87CEFA"
		LightAzure	:="74BBFB"
		cyan		:="00B7EB" 
		Azurebriliant	:="3399FF" 
		Blue		:="1F75FE"		;; Crayola

		pink		:="FFC0CB"
		lavender	:="DAAADB"
		lav_Floral	:="B57EDC"  
		purple		:="7030A0"

		brown_pale	:="987654"
		brown		:="964B00"
		brown_2		:="7C4800"
		brown_dark	:="654321" 
		
		white		:="FFFFFF"  
		gray_220	:="DCDCDC"		
		gray_192	:="C0C0C0"
		gray_128	:="808080"
		gray_96		:="606060"	
		black	 	:="000000"
	}
	if !tt_background
		tt_size:="s12", tt_font:="Calibri", tt_text:="white", tt_background:="green"
	tooltip .	
	ToolTipFont(tt_size, tt_font) 
	ToolTipColor(tt_background, tt_text) 
	SetTimer, Tooltip_Color_Remove, -5
}
Tooltip_Color_Remove() {                      ; to reset to regular tooltip after each use.
	ToolTipFont("Default", "Default") 
	ToolTipColor("Default", "Default") 
	SetTimer, Tooltip_Remove, -1500   ; my default remove time, can be overiden with a new Settimer.
}
Tooltip_Remove() {
	tooltip
}
;~~--------- Red, Yellow, Orange ------------------------------------
ToolTip_Color_Red() {
	Global
	tt_size:="s12", tt_font:="Calibri", tt_text:="white", tt_background:="red" 
	ToolTip_Color() 	
}
ToolTip_Color_Red1() {
	Global
	tt_size:="s12", tt_font:="Calibri", tt_text:=white, tt_background:=r_204 
	ToolTip_Color()
}
ToolTip_Color_Red2() {
	Global
	tt_size:="s12", tt_font:="Calibri", tt_text:=white, tt_background:=r_144 
	ToolTip_Color()
}
ToolTip_Color_Yellow() {
	Global
	tt_size:="s12", tt_font:="Calibri", tt_text:=brown_dark, tt_background:=yellow
	ToolTip_Color()
}
ToolTip_Color_Yellow1() {
	Global
	tt_size:="s12", tt_font:="Calibri", tt_text:=gray_96, tt_background:=y_Jonquil 
	ToolTip_Color()
}
ToolTip_Color_Orange() {
	Global
	tt_size:="s12", tt_font:="Calibri", tt_text:=white, tt_background:=orange 
	ToolTip_Color()
}
ToolTip_Color_Orange1() {
	Global
	tt_size:="s12", tt_font:="Calibri", tt_text:=white, tt_background:=o_Tangelo 
	ToolTip_Color()
}
;`` 
;~~--------- Green, Blue ------------------------------------
ToolTip_Color_Lime() {
	Global
	tt_size:="s12", tt_font:="Calibri", tt_text:=brown, tt_background:=lime 
	ToolTip_Color()
}
ToolTip_Color_Green() {
	Global
	tt_size:="s12", tt_font:="Calibri", tt_text:=white, tt_background:=green
	ToolTip_Color()
}
ToolTip_Color_Green01() {
	Global
	tt_size:="s12", tt_font:="Calibri", tt_text:=white, tt_background:=g_Kelly
	ToolTip_Color()
}
ToolTip_Color_Blue02() {
	Global
	tt_size:="s12", tt_font:="Calibri", tt_text:=gray_96, tt_background:=SkyBlue
	ToolTip_Color()
}
ToolTip_Color_Blue01() {
	Global
	tt_size:="s12", tt_font:="Calibri", tt_text:=white, tt_background:=Azurebriliant 
	ToolTip_Color()
}
ToolTip_Color_Blue() {
	Global
	tt_size:="s12", tt_font:="Calibri", tt_text:=white, tt_background:=Blue 
	ToolTip_Color()
}
ToolTip_Color_Cyan() {
	Global
	tt_size:="s12", tt_font:="Calibri", tt_text:=white, tt_background:=cyan 
	ToolTip_Color()
}
;`` 
;~~--------- Pink, White, Gray, Black ------------------------------------
ToolTip_Color_Pink() {
	Global
	tt_size:="s12", tt_font:="Calibri", tt_text:=brown, tt_background:=pink
	ToolTip_Color()
}
ToolTip_Color_Lavender() {
	Global
	tt_size:="s12", tt_font:="Calibri", tt_text:=white, tt_background:=lav_Floral 
	ToolTip_Color()
}
ToolTip_Color_Purple() {
	Global
	tt_size:="s12", tt_font:="Calibri", tt_text:=white, tt_background:=purple
	ToolTip_Color()
}
ToolTip_Color_Brown01() {
	Global
	tt_size:="s12", tt_font:="Calibri", tt_text:=white, tt_background:=brown_pale 
	ToolTip_Color()
}
ToolTip_Color_Brown() {
	Global
	tt_size:="s12", tt_font:="Calibri", tt_text:=white, tt_background:=brown 
	ToolTip_Color()
}
;`` end of fold-in
knightrule
Posts: 6
Joined: 24 May 2021, 02:23

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

20 Jan 2023, 14:13

boiler wrote:
20 Jan 2023, 13:17
Or write a function where you can pass the color to it, which is a much better approach.
That's a great idea, i'll be implementing that soon. I'm new to coding. Thanks Boiler.
paveld
Posts: 9
Joined: 01 Oct 2020, 05:28

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

25 Jan 2023, 04:22

hello guys, sorry, now that ahk v2 is in prod, would there be any chance to convert the script to v2?
i tried AHK-v2-script-converter, but the created v2 version doesnt work :cry:
LAPIII
Posts: 668
Joined: 01 Aug 2021, 06:01

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

18 Feb 2023, 05:21

@paveld Class ToolTipOptions is basically the same for version 2:

EwYqrYB259.jpg
EwYqrYB259.jpg (20.84 KiB) Viewed 2349 times
paveld
Posts: 9
Joined: 01 Oct 2020, 05:28

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

20 Feb 2023, 05:05

@LAPIII
GREAT! many thanks
:dance:
nelvin08
Posts: 97
Joined: 27 Mar 2022, 23:13

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

24 Sep 2023, 00:40

Thank you for this! it works like a charm

Although it's funny that if you don't put the ToolTipFont on each of the hotkey, it will apply to the whole script that uses ToolTips.

So in my case, I just put it at the top of my script (since I use the same font and size for around 5++ tooltips in my whole script. Thanks!
Teddles
Posts: 1
Joined: 27 Sep 2023, 06:57

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

27 Sep 2023, 07:02

Hi there, im fairly new to AHK

I tried to use the script, but the TooltipFont and ToolTipColor doesnt seem to work on the first tooltip i use, only the second and onwards, am i using the script incorrectly?

Code: Select all

ToolTipFont("s20", "Comic Sans MS")
ToolTipColor("Black", "White")
ToolTip, This doesnt work 
Sleep 3000

ToolTip, Now it works
Sleep 3000

ExitApp

; ToolTipOpt v1.004
; Changes:
;  v1.001 - Pass "Default" to restore a setting to default
;  v1.002 - ANSI compatibility
;  v1.003 - Added workarounds for ToolTip's parameter being overwritten
;           by code within the message hook.
;  v1.004 - Fixed text colour.
 
ToolTipFont(Options := "", Name := "", hwnd := "") {
    static hfont := 0
    if (hwnd = "")
        hfont := Options="Default" ? 0 : _TTG("Font", Options, Name), _TTHook()
    else
        DllCall("SendMessage", "ptr", hwnd, "uint", 0x30, "ptr", hfont, "ptr", 0)
}
 
ToolTipColor(Background := "", Text := "", hwnd := "") {
    static bc := "", tc := ""
    if (hwnd = "") {
        if (Background != "")
            bc := Background="Default" ? "" : _TTG("Color", Background)
        if (Text != "")
            tc := Text="Default" ? "" : _TTG("Color", Text)
        _TTHook()
    }
    else {
        VarSetCapacity(empty, 2, 0)
        DllCall("UxTheme.dll\SetWindowTheme", "ptr", hwnd, "ptr", 0
            , "ptr", (bc != "" && tc != "") ? &empty : 0)
        if (bc != "")
            DllCall("SendMessage", "ptr", hwnd, "uint", 1043, "ptr", bc, "ptr", 0)
        if (tc != "")
            DllCall("SendMessage", "ptr", hwnd, "uint", 1044, "ptr", tc, "ptr", 0)
    }
}
 
_TTHook() {
    static hook := 0
    if !hook
        hook := DllCall("SetWindowsHookExW", "int", 4
            , "ptr", RegisterCallback("_TTWndProc"), "ptr", 0
            , "uint", DllCall("GetCurrentThreadId"), "ptr")
}
 
_TTWndProc(nCode, _wp, _lp) {
    Critical 999
   ;lParam  := NumGet(_lp+0*A_PtrSize)
   ;wParam  := NumGet(_lp+1*A_PtrSize)
    uMsg    := NumGet(_lp+2*A_PtrSize, "uint")
    hwnd    := NumGet(_lp+3*A_PtrSize)
    if (nCode >= 0 && (uMsg = 1081 || uMsg = 1036)) {
        _hack_ = ahk_id %hwnd%
        WinGetClass wclass, %_hack_%
        if (wclass = "tooltips_class32") {
            ToolTipColor(,, hwnd)
            ToolTipFont(,, hwnd)
        }
    }
    return DllCall("CallNextHookEx", "ptr", 0, "int", nCode, "ptr", _wp, "ptr", _lp, "ptr")
}
 
_TTG(Cmd, Arg1, Arg2 := "") {
    static htext := 0, hgui := 0
    if !htext {
        Gui _TTG: Add, Text, +hwndhtext
        Gui _TTG: +hwndhgui +0x40000000
    }
    Gui _TTG: %Cmd%, %Arg1%, %Arg2%
    if (Cmd = "Font") {
        GuiControl _TTG: Font, %htext%
        SendMessage 0x31, 0, 0,, ahk_id %htext%
        return ErrorLevel
    }
    if (Cmd = "Color") {
        hdc := DllCall("GetDC", "ptr", htext, "ptr")
        SendMessage 0x138, hdc, htext,, ahk_id %hgui%
        clr := DllCall("GetBkColor", "ptr", hdc, "uint")
        DllCall("ReleaseDC", "ptr", htext, "ptr", hdc)
        return clr
    }
}
User avatar
rommmcek
Posts: 1477
Joined: 15 Aug 2014, 15:18

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

05 Oct 2023, 06:59

You are doing nothing wrong.
AutoHotkey's ToolTip time ago just underwent antiflickering measure, i.e. ToolTip is refreshed only if it's content is changed (at least this is my interpretation).
So to work around it, you can display some unique ToolTip beforehand the actual one, if a tiny flicker as a side effect isn't too big of a problem.
To make it more user friendly you can put it into the _TTG function.
Spoiler
P.s.: Also take a look to the Class ToolTipOptions. If you are new to Ahk slightly different syntax won't bother you, and the code is likely to be maintained in contrast to this one.
User avatar
Chrysalis
Posts: 3
Joined: 09 Feb 2021, 19:04

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

18 Jan 2024, 05:57

How to make the settings global for a script and all its hotkeys and functions?

Also there needs to be active tooltip for the commands to work. Example:

Code: Select all

Numpad1::
ToolTip, a
ToolTipFont("s11", "Consolas")
ToolTipColor("Black", "White")
ToolTip, Test
return
If you comment out ToolTip, a the Test is a normal tooltip.

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: fiendhunter and 177 guests