ToolTipEx - custom fonts and colors in ToolTips

Post your working scripts, libraries and tools
just me
Posts: 7294
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: ToolTipEx - custom fonts and colors in ToolTips

01 Oct 2014, 08:43

As I said, it's a replacement for the built-in ToolTip command.
Skrell
Posts: 166
Joined: 23 Jan 2014, 12:05

Re: ToolTipEx - custom fonts and colors in ToolTips

01 Oct 2014, 12:08

just me wrote:As I said, it's a replacement for the built-in ToolTip command.
Yes you're right my apologies...
Skrell
Posts: 166
Joined: 23 Jan 2014, 12:05

Re: ToolTipEx - custom fonts and colors in ToolTips

01 Oct 2014, 12:31

zcooler wrote:Hi just me!

This is very cool :D

I have a shell extension installed which displays dynamic data for certain media file types (.TS) on the tooltip in windows explorer. It would be awesome to be abled to make those quite boring looking tooltips nicer (which seems easy to do with this function). It would also be cool to exchange tooltip property labels, which in some cases doesn't describe the dynamic data that well.

My tooltip looks like this translated from Swedish:
Objecttype: TS-file
Size: 1,50 GB
Length: 01:07.57
Texting: S19E10 - “Castle Hill”
Stationname: Discovery Channel
I would like to exchange:
Objecttype: --> Container format:
Length: --> Duration:
Texting: --> Episode:
Stationname: --> Channel:

Is that possible with this function and if so how?

Regards
zcooler
Take a look at this script: http://www.autohotkey.com/board/topic/5 ... ip-window/

If you wrote a script to hook every time a tooltip is created, hide it, and then used the above script to get the text and tooltipex to then display it you could essentially have a script that replaces windows tooltips with custom ones...any takers??
zcooler
Posts: 455
Joined: 11 Jan 2014, 04:59

Re: ToolTipEx - custom fonts and colors in ToolTips

02 Oct 2014, 12:44

Skrell wrote:Just curious which shell extension is it ?
Oh, it is just a small plugin for displaying extended fileinfo/properties for tv recordings in the explorer. The plugin uses the MediaInfo API for retrieving the extra information. It is very useful when making scripts for the pvr software im using.
Skrell wrote:Take a look at this script: http://www.autohotkey.com/board/topic/5 ... ip-window/

If you wrote a script to hook every time a tooltip is created, hide it, and then used the above script to get the text and tooltipex to then display it you could essentially have a script that replaces windows tooltips with custom ones...any takers??
Very nice idea, Skrell :D I will definitely look into this as soon as having more free time.

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

Re: ToolTipEx - custom fonts and colors in ToolTips

04 Oct 2014, 22:50

Nice function. However, there's not much reason to limit yourself to the ToolTip API. Using a normal GUI would give a lot more flexibility. You could, for instance, display images, buttons or other controls. Just as a proof of concept, I've adapted just me's function to use GUI commands:

Code: Select all

; ======================================================================================================================
; ToolTipG()      Display ToolTips with custom fonts and colors using a GUI.
;                 Code based on just me's ToolTipEx.
; Requires format.ahk, which is distributed with AutoHotkey v2-alpha.
; Tested with:    AHK 1.1.16.05 (U32/U64)
; Tested on:      Win 7 Pro (x64)
; Parameters:
;     Text           -  the text to display in the ToolTip.
;                       If omitted or empty, the ToolTip will be destroyed.
;     X              -  the X position of the ToolTip.
;                       Default: "" (mouse cursor)
;     Y              -  the Y position of the ToolTip.
;                       Default: "" (mouse cursor)
;     WhichToolTip   -  the number of the ToolTip.
;                       Values:  1 - 20
;                       Default: 1
;     Font           -  Font options and name separated by a comma.
;                       Default: none (default GUI font)
;     BgColor        -  the background color of the ToolTip.
;                       Values:  RGB integer value or HTML color name.
;                       Default: "" (default color)
;     TxColor        -  the text color of the ToolTip.
;                       Values:  RGB integer value or HTML color name.
;                       Default: "" (default color)
;     Image          -  not implemented.
;                       Default: "" (no image)
;     CoordMode      -  the coordinate mode for the X and Y parameters, if specified.
;                       Values:  "C" (Client), "S" (Screen), "W" (Window)
;                       Default: "W" (CoordMode, ToolTip, Window)
; Return values:
;     On success: The HWND of the ToolTip window.
;     On failure: False (ErrorLevel contains additional informations)
; ======================================================================================================================
ToolTipG(Text:="", X:="", Y:="", WhichToolTip:=1, Font:="", BgColor:="", TxColor:="", Image:="", CoordMode:="W") {
   ; -------------------------------------------------------------------------------------------------------------------
   ; Check params
   TTTX := Text
   TTXP := X
   TTYP := Y
   TTIX := "ToolTip" (WhichToolTip = "" ? 1 : WhichToolTip)
   TTHF := Font = "" ? "" : StrSplit(Font, ",", " `t")
   TTBC := BgColor
   TTTC := TxColor
   TTIC := Image
   TTCM := CoordMode = "" ? "W" : SubStr(CoordMode, 1, 1)
   If TTXP Is Not Digit
      Return False, ErrorLevel := "Invalid parameter X-position!", False
   If TTYP Is Not Digit
      Return  False, ErrorLevel := "Invalid parameter Y-Position!", False
   If !InStr("CSW", CoordMode)
      Return False, ErrorLevel := "Invalid parameter CoordMode!", False
   ; -------------------------------------------------------------------------------------------------------------------
   ; Destroy the ToolTip window, if Text is empty
   If (TTTX = "") {
      Gui %TTIX%: Destroy
      Return True
   }
   ; -------------------------------------------------------------------------------------------------------------------
   ; Save thread settings.
   DHW := A_DetectHiddenWindows
   DetectHiddenWindows On
   LFW := WinExist()
   ; -------------------------------------------------------------------------------------------------------------------
   ; Get the virtual desktop rectangle
   SysGet, X, 76
   SysGet, Y, 77
   SysGet, W, 78
   SysGet, H, 79
   DTW := {L: X, T: Y, R: X + W, B: Y + H}
   ; -------------------------------------------------------------------------------------------------------------------
   ; Initialise the ToolTip coordinates. If either X or Y is empty, use the cursor position for the present.
   PT := {X: 0, Y: 0}
   If (TTXP = "") || (TTYP = "") {
      VarSetCapacity(Cursor, 8, 0)
      DllCall("User32.dll\GetCursorPos", "Ptr", &Cursor)
      Cursor := {X: NumGet(Cursor, 0, "Int"), Y: NumGet(Cursor, 4, "Int")}
      PT := {X: Cursor.X + 16, Y: Cursor.Y + 16}
   }
   ; -------------------------------------------------------------------------------------------------------------------
   ; If either X or Y  is specified, get the position of the active window considering CoordMode.
   Origin := {X: 0, Y: 0}
   If ((TTXP <> "") || (TTYP <> "")) && ((TTCM = "W") || (TTCM = "C")) { ; if (*aX || *aY) // Need the offsets.
      HWND := DllCall("User32.dll\GetForegroundWindow", "UPtr")
      If (TTCM = "W") {
         WinGetPos, X, Y, , , ahk_id %HWND%
         Origin := {X: X, Y: Y}
      }
      Else {
         VarSetCapacity(OriginPT, 8, 0)
         DllCall("User32.dll\ClientToScreen", "Ptr", HWND, "Ptr", &OriginPT)
         Origin := {X: NumGet(OriginPT, 0, "Int"), Y: NumGet(OriginPT, 0, "Int")}
      }
   }
   ; -------------------------------------------------------------------------------------------------------------------
   ; If either X or Y is specified, use the window related position for this parameter.
   If (TTXP <> "")
      PT.X := TTXP + Origin.X
   If (TTYP <> "")
      PT.Y := TTYP + Origin.Y
   ; -------------------------------------------------------------------------------------------------------------------
   ; If the ToolTip window doesn't exist, create it.
   Gui %TTIX%: +LastFoundExist
   If !TTHW := WinExist() {
      Gui %TTIX%: +AlwaysOnTop +HwndTTHW +ToolWindow -Caption -DPIScale
   }
   ; -------------------------------------------------------------------------------------------------------------------
   ; Update the text and the font and colors, if specified.
   If (TTBC = "")
      TTBC := format("{1:08x}", DllCall("GetSysColor", "int", 24))
   if (TTTC = "")
      TTTC := format("{1:08x}", DllCall("GetSysColor", "int", 23))
   Gui %TTIX%: Color, %TTTC% ; border
   If (TTIC <> "") {
      ; TODO: Add image
   }
   If (TTHF) ; font
      Gui %TTIX%: Font, % TTHF[1], % TTHF[2]
   ; -------------------------------------------------------------------------------------------------------------------
   ; (Re)create a sub-GUI to simplify text control sizing.
   Gui %TTIX%T: Destroy
   if TTHF
      Gui %TTIX%T: Font, % TTHF[1], % TTHF[2]
   Gui %TTIX%T: +Parent%TTIX% +HwndTTHWT -Caption 
   Gui %TTIX%T: Margin, 3, 2
   Gui %TTIX%T: Color, %TTBC%
   Gui %TTIX%T: Add, Text, c%TTTC%, %TTTX%
   Gui %TTIX%T: Show, NA x1 y1
   ; -------------------------------------------------------------------------------------------------------------------
   ; Get the ToolTip window dimensions.
   VarSetCapacity(RC, 16, 0)
   DllCall("User32.dll\GetWindowRect", "Ptr", TTHWT, "Ptr", &RC)
   TTRC := {L: NumGet(RC, 0, "Int"), T: NumGet(RC, 4, "Int"), R: NumGet(RC, 8, "Int"), B: NumGet(RC, 12, "Int")}
   TTW := TTRC.R - TTRC.L + 2
   TTH := TTRC.B - TTRC.T + 2
   ; -------------------------------------------------------------------------------------------------------------------
   ; Check if the Tooltip will be partially outside the virtual desktop and adjust the position, if necessary.
   If (PT.X + TTW >= DTW.R)
      PT.X := DTW.R - TTW - 1
   If (PT.Y + TTH >= DTW.B)
      PT.Y := DTW.B - TTH - 1
   ; -------------------------------------------------------------------------------------------------------------------
   ; Check if the cursor is inside the ToolTip window and adjust the position, if necessary.
   If (TTXP = "") || (TTYP = "") {
      TTRC.L := PT.X, TTRC.T := PT.Y, TTRC.R := TTRC.L + TTW, TTRC.B := TTRC.T + TTH
      If (Cursor.X >= TTRC.L) && (Cursor.X <= TTRC.R) && (Cursor.Y >= TTRC.T) && (Cursor.Y <= TTRC.B)
         PT.X := Cursor.X - TTW - 3, PT.Y := Cursor.Y - TTH - 3
   }
   ; -------------------------------------------------------------------------------------------------------------------
   ; Show the Tooltip using the final coordinates.
   Gui %TTIX%: Show, % "NA x" PT.X " y" PT.Y " w" TTW " h" TTH
   ; -------------------------------------------------------------------------------------------------------------------
   ; Restore thread settings.
   WinExist("ahk_id " LFW)
   DetectHiddenWindows %DHW%
   Return TTHW
}
I didn't bother to implement images, or do much testing, since I got bored. ;)
lexikos
Posts: 7085
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: ToolTipEx - custom fonts and colors in ToolTips

05 Oct 2014, 00:49

Rather than re-inventing the ToolTip command, one can affect its behaviour:
ToolTipFont / ToolTipColor - options for the ToolTip command
just me
Posts: 7294
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: ToolTipEx - custom fonts and colors in ToolTips

05 Oct 2014, 04:41

lexikos wrote:Rather than re-inventing the ToolTip command, one can affect its behaviour ...
I wasn't interested in re-inventing the command, I just wanted to show how easy the options could be added. ;)
lexikos
Posts: 7085
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: ToolTipEx - custom fonts and colors in ToolTips

06 Oct 2014, 00:44

You weren't interested, but you did it anyway. I showed an even easier way to add options, without reinventing the command.

Adding options to an existing command is easy. Doing it without making the usage hard to remember is less easy.
just me
Posts: 7294
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: ToolTipEx - custom fonts and colors in ToolTips

07 Oct 2014, 02:41

Just two thoughts:
  1. IMHO, everyone interested in customizing the ToolTips would willingly loop up the manual, if necessary.
  2. IMHO, calling a hook for every message sent to the thread causes an inadequate overhead for such a kind of task.
lexikos
Posts: 7085
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: ToolTipEx - custom fonts and colors in ToolTips

08 Oct 2014, 01:28

1. I'd still prefer to keep the usage simple, but I don't really care, which is another reason why I won't implement it.
2. As I said in the other thread, one could subclass the tooltip window class. Then the overhead would only be for messages sent to tooltips owned by the script, which is negligible. I just took the easiest (laziest) route. Although more than necessary, the overhead is generally irrelevant in most scripts.
just me
Posts: 7294
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: ToolTipEx - custom fonts and colors in ToolTips

08 Oct 2014, 03:45

lexikos wrote:As I said in the other thread, one could subclass the tooltip window class.
How?

Edit: Got it!
guest3456
Posts: 3145
Joined: 09 Oct 2013, 10:31

Re: ToolTipEx - custom fonts and colors in ToolTips

08 Oct 2014, 15:07

just me wrote:
lexikos wrote:As I said in the other thread, one could subclass the tooltip window class.
How?

Edit: Got it!
How? :)

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

Re: ToolTipEx - custom fonts and colors in ToolTips

09 Oct 2014, 03:00

You can use the same technique that I used to create glass frames around menus.
just me
Posts: 7294
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: ToolTipEx - custom fonts and colors in ToolTips

09 Oct 2014, 03:27

Code: Select all

_TTSubClass() {
   Static OrgWndProc := 0
   If !(OrgWndProc) {
      WindowProc := RegisterCallback("_TTWindowProc", "F")
      HTT := DllCall("User32.dll\CreateWindowEx", "UInt", 8, "Str", "tooltips_class32", "Ptr", 0, "UInt", 3
                    , "Int", 0, "Int", 0, "Int", 0, "Int", 0, "Ptr", A_ScriptHwnd, "Ptr", 0, "Ptr", 0, "Ptr", 0)
      If (A_PtrSize = 8)
         OrgWndProc := DllCall("User32.dll\SetClassLongPtr", "Ptr", HTT, "Int", -24, "Ptr", WindowProc, "UPtr")
      Else
         OrgWndProc := DllCall("User32.dll\SetClassLongW", "Ptr", HTT, "Int", -24, "Int", WindowProc, "UInt")
      DllCall("User32.dll\DestroyWindow", "Ptr", HTT)
   }
   Return OrgWndProc
}

_TTWindowProc(hWnd, uMsg, wParam, lParam) {
   Static OrgWndProc := 0
   Critical
   If !(OrgWndProc)
      OrgWndProc := _TTSubClass()
   If (uMsg = 1036) || (uMsg = 1081) {
      ToolTipMargins(,,,, hWnd)
      ToolTipTitle(,, hWnd)
      ToolTipColor(,, hWnd)
      ToolTipFont(,, hWnd)
   }
   Return DllCall(OrgWndProc, "Ptr", hWnd, "UInt", uMsg, "Ptr", wParam, "Ptr", lParam, "UInt")
}
Interestingly, I had to call SetClassLongW explicitely to make it work with ANSI on Win 8.1 (x64).
guest3456
Posts: 3145
Joined: 09 Oct 2013, 10:31

Re: ToolTipEx - custom fonts and colors in ToolTips

09 Oct 2014, 10:50

excellent thanks guys

User avatar
joedf
Posts: 7762
Joined: 29 Sep 2013, 17:08
Facebook: J0EDF
Google: +joedf
GitHub: joedf
Location: Canada
Contact:

Re: ToolTipEx - custom fonts and colors in ToolTips

09 Oct 2014, 10:57

So like a "window" in a window. O__o window-ception!
Guest

Re: ToolTipEx - custom fonts and colors in ToolTips

13 Oct 2014, 09:00

just me wrote:

Code: Select all

_TTSubClass() {
   Static OrgWndProc := 0
   If !(OrgWndProc) {
      WindowProc := RegisterCallback("_TTWindowProc", "F")
      HTT := DllCall("User32.dll\CreateWindowEx", "UInt", 8, "Str", "tooltips_class32", "Ptr", 0, "UInt", 3
                    , "Int", 0, "Int", 0, "Int", 0, "Int", 0, "Ptr", A_ScriptHwnd, "Ptr", 0, "Ptr", 0, "Ptr", 0)
      If (A_PtrSize = 8)
         OrgWndProc := DllCall("User32.dll\SetClassLongPtr", "Ptr", HTT, "Int", -24, "Ptr", WindowProc, "UPtr")
      Else
         OrgWndProc := DllCall("User32.dll\SetClassLongW", "Ptr", HTT, "Int", -24, "Int", WindowProc, "UInt")
      DllCall("User32.dll\DestroyWindow", "Ptr", HTT)
   }
   Return OrgWndProc
}

_TTWindowProc(hWnd, uMsg, wParam, lParam) {
   Static OrgWndProc := 0
   Critical
   If !(OrgWndProc)
      OrgWndProc := _TTSubClass()
   If (uMsg = 1036) || (uMsg = 1081) {
      ToolTipMargins(,,,, hWnd)
      ToolTipTitle(,, hWnd)
      ToolTipColor(,, hWnd)
      ToolTipFont(,, hWnd)
   }
   Return DllCall(OrgWndProc, "Ptr", hWnd, "UInt", uMsg, "Ptr", wParam, "Ptr", lParam, "UInt")
}
Interestingly, I had to call SetClassLongW explicitely to make it work with ANSI on Win 8.1 (x64).
Does this mean you're changing your code to subclass the tooltip window class?
just me
Posts: 7294
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: ToolTipEx - custom fonts and colors in ToolTips

14 Oct 2014, 01:37

No. This function doesn't need to subclass anything.
zcooler
Posts: 455
Joined: 11 Jan 2014, 04:59

Re: ToolTipEx - custom fonts and colors in ToolTips

02 May 2017, 16:33

just me wrote:Joedf, ToolTips only support icons (within the title, but the title text won't be drawn using the specified font's size), 16 * 16 on Win XP and also 32 * 32 on Vista+. Do you want them?
Hey just me,
I did some testing with TooltipEx() and AddTooltip() and this limitation is a total buzzkill. Although if using system icons they utilize the empty space under the title icon better (see AddTooltip() sample) and not just the row height of the title if applying a custom icon like in the ToolTipEx sample (see full size custom icon to the left of the ToolTipEx sample). It would surely be very intresting to know (I will have to ask) how the DVBViewer guys did it when adding the icons to their menu tooltips (see the samples to the left in image). Very cool when the icon arrow changes direction depending on which side (above or below) the tooltip is displayed of the RadioCheckButton.
tooltip_samples.jpg
tooltip_samples.jpg (90.99 KiB) Viewed 3447 times
just me
Posts: 7294
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: ToolTipEx - custom fonts and colors in ToolTips

03 May 2017, 10:33

Hi zcooler,

I'm pretty sure they are drawing the tooltip themselves in case they actually use a common tooltip control.
Very cool when the icon arrow changes direction depending on which side (above or below) the tooltip is displayed of the RadioCheckButton.
And very unnecessary, because the hilite color clearly indicates the menu item.

Return to “Scripts and Functions”

Who is online

Users browsing this forum: daywalker, hasantr, ilaoyao, yuchenoin and 13 guests