Page 4 of 5

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

Posted: 21 Apr 2022, 21:37
by boiler
Oh, wait. Sorry, it looks like the one I posted didn't have all the changes including the global declaration:

Code: Select all

#SingleInstance, Force
#Include C:\Users\LPIII\Documents\AutoHotkey\Lib\GDIP_All.ahk
SetWorkingDir, C:\Users\LPIII\Pictures\Captures   

ToolTipFont("s14", "Comic Sans MS") 
ToolTipColor("green", "white")
return

^+PrintScreen::
ToolTip, Active Window Screenshot, 1525, 0
SetTimer, RemoveToolTip, -500
WinGetPos, X, Y, W, H, A
Area := "(" X "|" Y "|" W "|" H ")"
FormatTime, DateTime,, d-M-yy h-mm-ss tt
WinGetActiveTitle, Title
Screenshot(Title "_" DateTime ".png")
return

Screenshot(OutFile)
{
global Area
pToken := Gdip_Startup()
snap := Gdip_BitmapFromScreen(Area)
Gdip_SaveBitmapToFile(snap, OutFile)
Gdip_DisposeImage(snap)		;Dispose of the bitmap to free memory.
Gdip_Shutdown( pToken ) 	;Turn off gdip
return
}

RemoveToolTip:
ToolTip
return

; ToolTipOpt v1.004
 
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
    }
}

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

Posted: 21 Apr 2022, 21:48
by LAPIII
@boiler This is terrific, thank you! :P

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

Posted: 06 Jun 2022, 04:38
by potscrubber
These wonderful wee functions no longer work for me in AHK 1.1.34.03. Specifically ToolTipFont: font and size. I just get the standard Windows tooltip.

If I downgrade to AHK 1.1.33.10 then functionality returns. Using AHK Unicode x64 in Win 10 x64 21H2.

Anyone else?

cheers.

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

Posted: 06 Jun 2022, 06:34
by just me
v1.1.34

Optimized ToolTip for cases where the text isn't changing, to reduce flicker and speed it up.
???

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

Posted: 06 Jun 2022, 17:33
by potscrubber
just me wrote:
06 Jun 2022, 06:34
v1.1.34

Optimized ToolTip for cases where the text isn't changing, to reduce flicker and speed it up.
???
Oh I missed that in the ChangleLog, yes thanks. Actually in a quick test it seemed to affect your ToolTipEx as well, in the font and size selection.

Perhaps @lexicos might be kind enough to update his script if there's any interest? It's over my pay grade to diagnose.

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

Posted: 08 Jun 2022, 01:28
by chaoscreater
potscrubber wrote:
06 Jun 2022, 04:38
These wonderful wee functions no longer work for me in AHK 1.1.34.03. Specifically ToolTipFont: font and size. I just get the standard Windows tooltip.

If I downgrade to AHK 1.1.33.10 then functionality returns. Using AHK Unicode x64 in Win 10 x64 21H2.

Anyone else?

cheers.
same. Doesn't work with latest AHK version...

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

Posted: 11 Jun 2022, 03:48
by just me
I doubt that lexicos can help here, but maybe @lexikos? ;)

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

Posted: 11 Jun 2022, 05:51
by boiler
just me wrote: I doubt that lexicos can help here, but maybe @lexikos? ;)
Image

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

Posted: 12 Jun 2022, 04:52
by just me
I think I found the reason:

Code: Select all

script2.cpp:
	// v1.1.34: Avoid TTM_UPDATETIPTEXT if the text hasn't changed, to reduce flicker.  The behaviour described
	// above could not be replicated, EVEN ON WINDOWS XP.  Whether it was ever observed on other OSes is unknown.
	if (!newly_created && !ToolTipTextEquals(tip_hwnd, aText))
		SendMessage(tip_hwnd, TTM_UPDATETIPTEXT, 0, (LPARAM)&ti);
ToolTipFont / ToolTipColor depend on the TTM_UPDATETIPTEXT message.

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

Posted: 28 Sep 2022, 14:56
by Spitzi
So, any update on the ToolTipFont / ToolTipColor issue?

Would be sad to loose that functionality... I just downgraded to 1.1.33.10 to have it back!

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

Posted: 28 Sep 2022, 18:13
by potscrubber
Yeah, I compile with the 1.1.33.10 binary for one particular program I distribute where big friendly tooltips are very helpful to the users.

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

Posted: 28 Sep 2022, 18:14
by potscrubber
just me wrote:
12 Jun 2022, 04:52
I think I found the reason:

Code: Select all

script2.cpp:
	// v1.1.34: Avoid TTM_UPDATETIPTEXT if the text hasn't changed, to reduce flicker.  The behaviour described
	// above could not be replicated, EVEN ON WINDOWS XP.  Whether it was ever observed on other OSes is unknown.
	if (!newly_created && !ToolTipTextEquals(tip_hwnd, aText))
		SendMessage(tip_hwnd, TTM_UPDATETIPTEXT, 0, (LPARAM)&ti);
ToolTipFont / ToolTipColor depend on the TTM_UPDATETIPTEXT message.
Thanks for getting to the bottom of it. I guess one could fork AHK and revert for that if "one" was so motivated!

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

Posted: 29 Sep 2022, 03:34
by Animan8000
There are anyway better ToolTip libraries out there, so it shouldn't be a major deal if this one broke accidentally. The last time I used this library here (before ToolTips themselves got patches a while ago), it had flickering, is CPU only and can consume bit much resources, and color accuracy problems, where the specified RGB values are incorrect in some cases, though, a normal person may not notice the minor difference.

Other libraries (especially some really good ones that are barely known at this point) do fix the flicker issues, offer better performance, accurate RGB and some use even the GPU for rendering them + far more opportunities to design and draw them the way you like.

Two I can recommend are ShinsOverlayClass and BeautifulToolTip. TextRender might be also somewhat good now after getting some updates, I only tried an older version in the past that had a few small issues.

https://github.com/Spawnova/ShinsOverlayClass
https://github.com/telppa/BeautifulToolTip
https://github.com/iseahound/TextRender

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

Posted: 04 Oct 2022, 08:10
by bestuser
Awesome! Thank you

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

Posted: 15 Jan 2023, 06:43
by knightrule
Tested on AHK 1.1.36.02

Code: Select all

if !initialize {
	initialize:= 1
	tooltip just need a starting tooltip before TooltipColor can work
	tt_size:="s12", tt_font:="Calibri", tt_text:="white", tt_background:="red" 
	ToolTipFont(tt_size, tt_font) 
	ToolTipColor(tt_background, tt_text) 
}	

tooltip TooltipColor should work now

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

Posted: 16 Jan 2023, 16:13
by LAPIII
Now that I'm on Windows 11, this doesn't work:

Code: Select all

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



; ToolTipOpt v1.004
 
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
    }
}


Re: ToolTipFont / ToolTipColor - options for the ToolTip command

Posted: 16 Jan 2023, 17:13
by boiler
You might be right (I don't have Windows 11 installed in order to check), but it could be the window that is active when you're running it is near the right side of the screen, and the 1025 is relative to the active window, which could cause the tooltip to be off the screen. To perform a more definitive check, see if this displays it at the upper-left corner of the screen:

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



; ToolTipOpt v1.004
 
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
    }
}

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

Posted: 16 Jan 2023, 19:20
by ntepa

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



; ToolTipOpt v1.004
 
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
    }
}
It looks like this in Windows 11:
tooltip.png
tooltip.png (1.63 KiB) Viewed 3443 times

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

Posted: 16 Jan 2023, 23:13
by LAPIII
Yes, I just tested and I see it in the upper left corner. However, I can't change the font or color.

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

Posted: 17 Jan 2023, 20:20
by knightrule
Broken since AHK 1.1.34.00 this is my work around on AHK 1.1.36.02 Window 10.:

Code: Select all

ToolTip_Color_Green()  						; benchmark: 30.4ms vs regular tooltip 15.0 ms
	tooltip Test - this is green				; if tooltip has not been cleared, then each additional 
	Sleep 2000									; ToolTip_Color has the same benchmark as regular tooltip
	ToolTip_Color_Red() 
	tooltip Test - this is red

ToolTip_Color() {
	Global
	if !cyan {				; my custom colors
		red:="red"
		darkred		:="B22222"
		orange		:="FFA500"
		darkorange	:="FF8C00"
		yellow		:="yellow"
		yellow1		:="ffdf00"
		magenta	:="FF00FF"	 	
		
		green		:="008000"
		green1		:="54b948"
		lime		:="9ACD32"
		olive		:="808000"
		darkolive	:="556B2F"

		blue		:="0066FF"
		blue1		:="0000FF"
		blue2		:="007dc5"
		navy		:="000080"
		teal			:="teal"
		skyblue		:="3BA4E8"
		cyan		:="00B0F0"
		pink		:="FFC0CB"
		lavender	:="DAAADB"
		purple		:="7030A0"

		silver		:="C0C0C0"
		gray		:="808080"
		darkgray	:="696969"
		black		:="black"
	}
	if !tt_background					; if font and color is not specified use default
		tt_size:="s12", tt_font:="Calibri", tt_text:="white", tt_background:="green"
	tooltip .								; this line is the work around
	ToolTipFont(tt_size, tt_font) 
	ToolTipColor(tt_background, tt_text) 
	SetTimer, Tooltip_Color_Remove, -50		; set color back to default after each use
}
ToolTip_Color_Red() {
	Global
	tt_size:="s12", tt_font:="Calibri", tt_text:="white", tt_background:="red" 
	ToolTip_Color() 	
}
ToolTip_Color_Blue() {
	Global
	tt_size:="s12", tt_font:="Calibri", tt_text:="white", tt_background:="blue" 
	ToolTip_Color()
}
ToolTip_Color_Green() {
	Global
	tt_size:="s12", tt_font:="Calibri", tt_text:="white", tt_background:="green"
	ToolTip_Color()
}
Tooltip_Color_Remove() {
	ToolTipFont("Default", "Default") 
	ToolTipColor("Default", "Default") 
	SetTimer, Tooltip_Remove, -1500
}
Tooltip_Remove() {
	tooltip
}