A bigger tooltip

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Gregorian
Posts: 22
Joined: 29 Aug 2020, 09:02

A bigger tooltip

22 Oct 2020, 17:03

All I want is a tooltip that is bigger. That's it.

Now, I got many recommendations, like Fnt Library v3.0. I am totally overwhelmed by the functionality of it, and I have no idea how to use it. I'm not a programmer. And I don't need anything fancy.

I really just want a bigger tooltip...

Can someone help me how to do that, please?
User avatar
mikeyww
Posts: 26936
Joined: 09 Sep 2014, 18:38

Re: A bigger tooltip

22 Oct 2020, 17:17

Code: Select all

Global guiWidth := 410
Gui, Tip:New, -Caption Border
Gui, Font, s14
Gui, Color, E1DC4E
Gui, Add, Text, w%guiWidth% vtipText, Test
tip("This kinda looks like a tooltip, but it's bigger.")
Return

TipGuiEscape:
ExitApp

tip(text) {
 GuiControl, Text, tipText, %text%
 Gui, Tip:Show, w%guiWidth%
}
Gregorian
Posts: 22
Joined: 29 Aug 2020, 09:02

Re: A bigger tooltip

22 Oct 2020, 17:46

Unfortunately that is no use to me, because it goes into the background as soon as I click anywhere in my program. Also, I need the tooltip to be in the top left corner... like a tooltip.
I would like to have a real tooltip, just bigger.
User avatar
mikeyww
Posts: 26936
Joined: 09 Sep 2014, 18:38

Re: A bigger tooltip

22 Oct 2020, 19:35

No problem. If needed, Gui can be positioned where you want, and also set to on-top.

Code: Select all

tip("This kinda looks like a tooltip, but it's bigger.", 20, 20, 1200)
MsgBox, Done.
Return

TipGuiEscape:
ExitApp

TipOff:
Gui, Tip:Hide
Return

tip(text := "", x := 10, y := 10, duration := 0, wait := False) {
 Static tipSetup := False, tipWidth := 230, tipText
 If !tipSetup {
  Gui, Tip:New, -Caption Border +AlwaysOnTop
  Gui, Font, s9
  Gui, Color, FFFFA2
  Gui, Add, Text, w%tipWidth% vtipText, Tooltip
  tipSetup := True
 }
 If text {
  GuiControl, Text, tipText, %text%
  WinGetActiveTitle, title
  Gui, Tip:Show, x%x% y%y% w%tipWidth%
  WinActivate, %title%
  If duration
   If wait
    Sleep, %duration%
   Else SetTimer, TipOff, % -1 * duration
 }
 If !text || duration && wait
  Gosub, TipOff
}
Gregorian
Posts: 22
Joined: 29 Aug 2020, 09:02

Re: A bigger tooltip

23 Oct 2020, 02:01

mikeyww wrote:
22 Oct 2020, 19:35
No problem. If needed, Gui can be positioned where you want, and also set to on-top.
I tried your code. It works fine on its own.
But when I combine it with my other autohotkey script, not only does it stop working, it also makes my other AHK script not work anymore.

Here is my script that doesn't work with your code:

Code: Select all

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

CoordMode, ToolTip, Screen

TipGuiEscape:
ExitApp

TipOff:
Gui, Tip:Hide
Return

tip(text := "", x := 0, y := 0, duration := 0, wait := False) {
 Static tipSetup := False, tipWidth := 340, tipText
 If !tipSetup {
  Gui, Tip:New, -Caption Border +AlwaysOnTop ;  Gui, Tip:New, -Caption Border +AlwaysOnTop
  Gui, Font, s19
  Gui, Color, FFFFA2
  Gui, Add, Text, w%tipWidth% vtipText, Tooltip ;  Gui, Add, Text, w%tipWidth% vtipText, Tooltip 
  tipSetup := True
 }
 If text {
  GuiControl, Text, tipText, %text%
  WinGetActiveTitle, title
  Gui, Tip:Show, x%x% y%y% w%tipWidth%
  WinActivate, %title%

 }
 If !text || duration && wait
  Gosub, TipOff
}


#IfWinActive ahk_exe Resolve.exe
{
ALL_HOTKEYS:=1
Tab::
if (ALL_HOTKEYS=0)
	{
	Gui, Tip:Hide
	ALL_HOTKEYS:=1
	}
else
	{
	tip("ALL HOTKEYS ARE DISABLED", 0, 0, 1000)
	ALL_HOTKEYS:=0
	}
DetectHiddenWindows, On
WM_COMMAND := 0x111
ID_FILE_SUSPEND := 65404
PostMessage, WM_COMMAND, ID_FILE_SUSPEND,,, %A_WorkingDir%\quick zoom.ahk ahk_class AutoHotkey
PostMessage, WM_COMMAND, ID_FILE_SUSPEND,,, %A_WorkingDir%\B = Back to last stop and play.ahk ahk_class AutoHotkey
PostMessage, WM_COMMAND, ID_FILE_SUSPEND,,, %A_WorkingDir%\TimeLineClick-master\TimelineClick.ahk ahk_class AutoHotkey
Return
}
User avatar
mikeyww
Posts: 26936
Joined: 09 Sep 2014, 18:38

Re: A bigger tooltip

23 Oct 2020, 06:34

Sorry I neglected to explain how the function works!

If you want to hide the tip, use tip(). Alternatively, you can specify the duration as a parameter.

CoordMode has no effect on the function. Gui uses absolute coordinates.

Read about #If. It is used only for hotkeys and hotstrings, not running code. Therefore, ALL_HOTKEYS:=1 will never execute.
User avatar
boiler
Posts: 16951
Joined: 21 Dec 2014, 02:44

Re: A bigger tooltip

23 Oct 2020, 11:02

If you just want the ToolTip itself to be larger and it's okay if the font is the normal size, you can just put whitespace around the text in a regular ToolTip to make it larger, like this:

Code: Select all

ToolTip, % "`n`n     This is a larger ToolTip     `n`n "
Sleep, 3000
ExitApp
teadrinker
Posts: 4330
Joined: 29 Mar 2015, 09:41
Contact:

Re: A bigger tooltip

23 Oct 2020, 12:01

Another one big tooltip:

Code: Select all

title := "Hello,"
text := "This is my custom ToolTip!`nIt will disappear in five seconds."

hToolTip := CustomToolTip(text,,, title, 1, true, 0xFFC141, 0x50669F, "Calibri", "s18", true, 5000)
                          
Timer := Func("UpdateText").Bind(hToolTip, [ StrReplace(text, "five seconds", "one second")
                                              , StrReplace(text, "five", "two")
                                              , StrReplace(text, "five", "three")
                                              , StrReplace(text, "five", "four") ])
SetTimer, % Timer, 1000
Return

CustomToolTip( text, x := "", y := "", title := ""
             , icon := 0  ; can be 1 — Info, 2 — Warning, 3 — Error, if greater than 3 — hIcon
             , closeButton := false, backColor := "", textColor := 0
             , fontName := "", fontOptions := ""  ; like in GUI
             , isBallon := false, timeout := "", maxWidth := 600 )
{
   static ttStyles := (TTS_NOPREFIX := 2) | (TTS_ALWAYSTIP := 1), TTS_BALLOON := 0x40, TTS_CLOSE := 0x80
        , TTF_TRACK := 0x20, TTF_ABSOLUTE := 0x80
        , TTM_SETMAXTIPWIDTH := 0x418, TTM_TRACKACTIVATE := 0x411, TTM_TRACKPOSITION := 0x412
        , TTM_SETTIPBKCOLOR := 0x413, TTM_SETTIPTEXTCOLOR := 0x414
        , TTM_ADDTOOL        := A_IsUnicode ? 0x432 : 0x404
        , TTM_SETTITLE       := A_IsUnicode ? 0x421 : 0x420
        , TTM_UPDATETIPTEXT  := A_IsUnicode ? 0x439 : 0x40C
        , exStyles := (WS_EX_TOPMOST := 0x00000008) | (WS_EX_COMPOSITED := 0x2000000) | (WS_EX_LAYERED := 0x80000)
        , WM_SETFONT := 0x30, WM_GETFONT := 0x31
   
   dhwPrev := A_DetectHiddenWindows, defGuiPrev := A_DefaultGui, lastFoundPrev := WinExist()
   DetectHiddenWindows, On
   hWnd := DllCall("CreateWindowEx", "UInt", exStyles, "Str", "tooltips_class32", "Str", ""
                                   , "UInt", ttStyles | TTS_CLOSE * !!CloseButton | TTS_BALLOON * !!isBallon
                                   , "Int", 0, "Int", 0, "Int", 0, "Int", 0, "Ptr", 0, "Ptr", 0, "Ptr", 0, "Ptr", 0, "Ptr")
   WinExist("ahk_id" . hWnd)
   if (textColor != 0 || backColor != "") {
      DllCall("UxTheme\SetWindowTheme", "Ptr", hWnd, "Ptr", 0, "UShortP", empty := 0)
      ByteSwap := Func("DllCall").Bind("msvcr100\_byteswap_ulong", "UInt")
      SendMessage, TTM_SETTIPBKCOLOR  , ByteSwap.Call(backColor << 8)
      SendMessage, TTM_SETTIPTEXTCOLOR, ByteSwap.Call(textColor << 8)
   }
   if (fontName || fontOptions) {
      Gui, New
      Gui, Font, % fontOptions, % fontName
      Gui, Add, Text, hwndhText
      SendMessage, WM_GETFONT,,,, ahk_id %hText%
      SendMessage, WM_SETFONT, ErrorLevel
      Gui, Destroy
      Gui, %defGuiPrev%: Default
   }
   VarSetCapacity(TOOLINFO, sz := 24 + A_PtrSize*6, 0)
   NumPut(sz, TOOLINFO)
   NumPut(TTF_TRACK | TTF_ABSOLUTE * !isBallon, TOOLINFO, 4)
   NumPut(&text, TOOLINFO, 24 + A_PtrSize*3)
   
   if (x = "" || y = "")
      DllCall("GetCursorPos", "Int64P", pt)
   (x = "" && x := (pt & 0xFFFFFFFF) + 15), (y = "" && y := (pt >> 32) + 15)
   
   SendMessage, TTM_SETTITLE      , icon, &title
   SendMessage, TTM_TRACKPOSITION ,     , x | (y << 16)
   SendMessage, TTM_SETMAXTIPWIDTH,     , maxWidth
   SendMessage, TTM_ADDTOOL       ,     , &TOOLINFO
   SendMessage, TTM_UPDATETIPTEXT ,     , &TOOLINFO
   SendMessage, TTM_TRACKACTIVATE , true, &TOOLINFO
   
   if timeout {
      Timer := Func("DllCall").Bind("DestroyWindow", "Ptr", hWnd)
      SetTimer, % Timer, % "-" . timeout
   }
   DetectHiddenWindows, % dhwPrev
   WinExist("ahk_id" . lastFoundPrev)
   Return hWnd
}

UpdateText(hTooltip, TextArray) {
   static TTM_UPDATETIPTEXT := A_IsUnicode ? 0x439 : 0x40C
   text := TextArray.Pop()
   VarSetCapacity(TOOLINFO, sz := 24 + A_PtrSize*6, 0)
   NumPut(sz, TOOLINFO)
   NumPut(&text, TOOLINFO, 24 + A_PtrSize*3)
   SendMessage, TTM_UPDATETIPTEXT,, &TOOLINFO,, ahk_id %hTooltip%
   if (TextArray[1] = "")
      SetTimer,, Delete
}
ahk7
Posts: 575
Joined: 06 Nov 2013, 16:35

Re: A bigger tooltip

23 Oct 2020, 12:38

Lexikos posted ToolTipFont https://www.autohotkey.com/boards/viewtopic.php?f=6&t=4777 (haven't compared it to solution above)
User avatar
mikeyww
Posts: 26936
Joined: 09 Sep 2014, 18:38

Re: A bigger tooltip

23 Oct 2020, 12:42

Awesome-- lots of options!
Gregorian
Posts: 22
Joined: 29 Aug 2020, 09:02

Re: A bigger tooltip

23 Oct 2020, 23:05

mikeyww wrote:
23 Oct 2020, 06:34
Sorry I neglected to explain how the function works!

If you want to hide the tip, use tip(). Alternatively, you can specify the duration as a parameter.

CoordMode has no effect on the function. Gui uses absolute coordinates.

Read about #If. It is used only for hotkeys and hotstrings, not running code. Therefore, ALL_HOTKEYS:=1 will never execute.
Thank you. Could you do me the big, big favor and please tell me how I need to rewrite my code to make it work?
I just don't understand how to do it.
User avatar
mikeyww
Posts: 26936
Joined: 09 Sep 2014, 18:38

Re: A bigger tooltip

24 Oct 2020, 07:28

An example is below. I fixed one issue in the function. You would need to insert any code that actually disables the keys. Try this script first, to see how it works.

Code: Select all

SendMode Input
status := ["Disabled", "Enabled"], colr := ["E1B9B7", "FFFFA2"], ALL_HOTKEYS := True

#IfWinActive ahk_exe Resolve.exe
Tab::
tip("Hotkeys: " status[(ALL_HOTKEYS := !ALL_HOTKEYS) + 1], 0, 0, 1000, colr[ALL_HOTKEYS + 1])
SoundBeep, ALL_HOTKEYS ? 1500 : 1000, 35
; More code here that does what you want
Return
#IfWinActive

TipGuiEscape:
ExitApp

TipOff:
Gui, Tip:Hide
Return

tip(ttext := "", x := 10, y := 10, duration := 0, colr := "FFFFA2", wait := False) {
 Static tipSetup := False, tipWidth := 230, tipText
 If !tipSetup {
  Gui, Tip:New, -Caption Border +AlwaysOnTop
  Gui, Font, s10
  Gui, Color, % colr.1
  Gui, Add, Text, w%tipWidth% vtipText, Tooltip
  tipSetup := True
 }
 If ttext {
  WinGetActiveTitle, title
  GuiControl, Tip:Text, tipText, %ttext%
  Gui, Tip:Color, %colr%
  Gui, Tip:Show, x%x% y%y% w%tipWidth%
  WinActivate, %title%
  If duration
   If wait
    Sleep, %duration%
   Else SetTimer, TipOff, % -1 * duration
 }
 If !ttext || duration && wait
  Gosub, TipOff
}
Gregorian
Posts: 22
Joined: 29 Aug 2020, 09:02

Re: A bigger tooltip

24 Oct 2020, 09:49

Sorry to bother you once more, but you are already so experienced with autohotkey that I have trouble to understand your code.
I need the tooltip to stay there when it says "HOTKEYS: DISABLED". When it says "HOTKEYS: ENABLED" it should only stay there for 2 seconds, and then disappear.
Could you please help me to do that?
User avatar
mikeyww
Posts: 26936
Joined: 09 Sep 2014, 18:38

Re: A bigger tooltip

24 Oct 2020, 09:59

Maybe this helps.

Code: Select all

SendMode Input
tipY := tipX := 0 ; Coordinates for the tooltip

#IfWinActive ahk_exe Resolve.exe
Tab::Gosub, % (ALL_HOTKEYS := !ALL_HOTKEYS) ? "Enable" : "Disable" ; Toggle; call one of the subroutines.
#IfWinActive

Disable: ; Disable the hotkeys
SoundBeep, 1000, 30
; Add code here
tip("Hotkeys: Disabled", tipX, tipY,, "E1B9B7") ; Persistent; use color specified here
Return

Enable: ; Enable the hotkeys
SoundBeep, 1500, 30
; Add code here
tip("Hotkeys: Enabled", tipX, tipY, 2000) ; Two seconds, default color
Return

TipGuiEscape:
ExitApp

TipOff:
Gui, Tip:Hide
Return

tip(ttext := "", x := 10, y := 10, duration := 0, colr := "FFFFA2", wait := False) {
 Static tipSetup := False, tipWidth := 230, tipText
 If !tipSetup {
  Gui, Tip:New, -Caption Border +AlwaysOnTop
  Gui, Font, s10
  Gui, Color, % colr.1
  Gui, Add, Text, w%tipWidth% vtipText, Tooltip
  tipSetup := True
 }
 If ttext {
  WinGetActiveTitle, title
  GuiControl, Tip:Text, tipText, %ttext%
  Gui, Tip:Color, %colr%
  SetTimer, TipOff, Off
  Gui, Tip:Show, x%x% y%y% w%tipWidth%
  WinActivate, %title%
  If duration
   If wait
    Sleep, %duration%
   Else SetTimer, TipOff, % -1 * duration
 }
 If !ttext || duration && wait
  Gosub, TipOff
}
Gregorian
Posts: 22
Joined: 29 Aug 2020, 09:02

Re: A bigger tooltip

24 Oct 2020, 14:46

So, the the tooltip (GUI) works great now, just as I want it. But the AHK script suspension doesn't work.

I just inserted the script suspension commands where you wrote that I should write the code. But they don't do anything. Could you please tell me how to make this script work?

Code: Select all

SendMode Input
tipY := tipX := 0 ; Coordinates for the tooltip

#IfWinActive ahk_exe Resolve.exe
Tab::Gosub, % (ALL_HOTKEYS := !ALL_HOTKEYS) ? "Disable" : "Enable" ; Toggle; call one of the subroutines.
#IfWinActive

Disable: ; Disable the hotkeys
SoundBeep, 1000, 30
; Add code here
DetectHiddenWindows, On
WM_COMMAND := 0x111
ID_FILE_SUSPEND := 65404
PostMessage, WM_COMMAND, ID_FILE_SUSPEND,,, %A_WorkingDir%\quick zoom.ahk ahk_class AutoHotkey
PostMessage, WM_COMMAND, ID_FILE_SUSPEND,,, %A_WorkingDir%\B = Back to last stop and play.ahk ahk_class AutoHotkey
PostMessage, WM_COMMAND, ID_FILE_SUSPEND,,, %A_WorkingDir%\TimeLineClick-master\TimelineClick.ahk ahk_class AutoHotkey
PostMessage, WM_COMMAND, ID_FILE_SUSPEND,,, %A_WorkingDir%\Ripple delete start to playhead.ahk ahk_class AutoHotkey
PostMessage, WM_COMMAND, ID_FILE_SUSPEND,,, %A_WorkingDir%\Ripple delete end to playhead.ahk ahk_class AutoHotkey
PostMessage, WM_COMMAND, ID_FILE_SUSPEND,,, %A_WorkingDir%\Change transition length.ahk ahk_class AutoHotkey
PostMessage, WM_COMMAND, ID_FILE_SUSPEND,,, %A_WorkingDir%\Create Cross Dissolve Transition.ahk ahk_class AutoHotkey
PostMessage, WM_COMMAND, ID_FILE_SUSPEND,,, %A_WorkingDir%\Change Cross Dissolve Transition to Smooth Cut transition.ahk ahk_class AutoHotkey
PostMessage, WM_COMMAND, ID_FILE_SUSPEND,,, %A_WorkingDir%\Change Cross Dissolve Transition to Dip to Color Dissolve Transition.ahk ahk_class AutoHotkey
PostMessage, WM_COMMAND, ID_FILE_SUSPEND,,, %A_WorkingDir%\J and L increase volume.ahk ahk_class AutoHotkey
PostMessage, WM_COMMAND, ID_FILE_SUSPEND,,, %A_WorkingDir%\Click horizontal scroll bar.ahk ahk_class AutoHotkey
tip("Hotkeys: Disabled", tipX, tipY,, "E1B9B7") ; Persistent; use color specified here
Return

Enable: ; Enable the hotkeys
SoundBeep, 1500, 30
; Add code here
DetectHiddenWindows, On
WM_COMMAND := 0x111
ID_FILE_SUSPEND := 65404
PostMessage, WM_COMMAND, ID_FILE_SUSPEND,,, %A_WorkingDir%\quick zoom.ahk ahk_class AutoHotkey
PostMessage, WM_COMMAND, ID_FILE_SUSPEND,,, %A_WorkingDir%\B = Back to last stop and play.ahk ahk_class AutoHotkey
PostMessage, WM_COMMAND, ID_FILE_SUSPEND,,, %A_WorkingDir%\TimeLineClick-master\TimelineClick.ahk ahk_class AutoHotkey
PostMessage, WM_COMMAND, ID_FILE_SUSPEND,,, %A_WorkingDir%\Ripple delete start to playhead.ahk ahk_class AutoHotkey
PostMessage, WM_COMMAND, ID_FILE_SUSPEND,,, %A_WorkingDir%\Ripple delete end to playhead.ahk ahk_class AutoHotkey
PostMessage, WM_COMMAND, ID_FILE_SUSPEND,,, %A_WorkingDir%\Change transition length.ahk ahk_class AutoHotkey
PostMessage, WM_COMMAND, ID_FILE_SUSPEND,,, %A_WorkingDir%\Create Cross Dissolve Transition.ahk ahk_class AutoHotkey
PostMessage, WM_COMMAND, ID_FILE_SUSPEND,,, %A_WorkingDir%\Change Cross Dissolve Transition to Smooth Cut transition.ahk ahk_class AutoHotkey
PostMessage, WM_COMMAND, ID_FILE_SUSPEND,,, %A_WorkingDir%\Change Cross Dissolve Transition to Dip to Color Dissolve Transition.ahk ahk_class AutoHotkey
PostMessage, WM_COMMAND, ID_FILE_SUSPEND,,, %A_WorkingDir%\J and L increase volume.ahk ahk_class AutoHotkey
PostMessage, WM_COMMAND, ID_FILE_SUSPEND,,, %A_WorkingDir%\Click horizontal scroll bar.ahk ahk_class AutoHotkey
tip("Hotkeys: Enabled", tipX, tipY, 2000) ; Two seconds, default color
Return

TipGuiEscape:
ExitApp

TipOff:
Gui, Tip:Hide
Return

tip(ttext := "", x := 10, y := 10, duration := 0, colr := "FFFFA2", wait := False) {
 Static tipSetup := False, tipWidth := 260, tipText
 If !tipSetup {
  Gui, Tip:New, -Caption Border +AlwaysOnTop
  Gui, Font, s20
  Gui, Color, % colr.1
  Gui, Add, Text, w%tipWidth% vtipText, Tooltip
  tipSetup := True
 }
 If ttext {
  WinGetActiveTitle, title
  GuiControl, Tip:Text, tipText, %ttext%
  Gui, Tip:Color, %colr%
  SetTimer, TipOff, Off
  Gui, Tip:Show, x%x% y%y% w%tipWidth%
  WinActivate, %title%
  If duration
   If wait
    Sleep, %duration%
   Else SetTimer, TipOff, % -1 * duration
 }
 If !ttext || duration && wait
  Gosub, TipOff
}
User avatar
mikeyww
Posts: 26936
Joined: 09 Sep 2014, 18:38

Re: A bigger tooltip

24 Oct 2020, 21:27

I am assuming that you would like the "Enable" routine to enable your keys, and "Disable" to disable them, and that you have working code to do that. It would not really make sense to have duplicated your code (the same set of commands) in both sections, right?

Are you really running all of those scripts at the same time? Could you combine them for simplicity and ease of management?

Beyond this, I cannot advise you, because I do not have the knowledge about PostMessage. Others may be able to reply and help. Since you have a completely different question at hand, you might want to create a new post to ask about your hotkey question that is unrelated to the tooltip. That is up to you, but it might affect who looks at the message.
User avatar
DataLife
Posts: 447
Joined: 29 Sep 2013, 19:52

Re: A bigger tooltip

12 Jan 2024, 01:15

teadrinker wrote:
23 Oct 2020, 12:01
Another one big tooltip:

Code: Select all

title := "Hello,"
text := "This is my custom ToolTip!`nIt will disappear in five seconds."

hToolTip := CustomToolTip(text,,, title, 1, true, 0xFFC141, 0x50669F, "Calibri", "s18", true, 5000)
                          
Timer := Func("UpdateText").Bind(hToolTip, [ StrReplace(text, "five seconds", "one second")
                                              , StrReplace(text, "five", "two")
                                              , StrReplace(text, "five", "three")
                                              , StrReplace(text, "five", "four") ])
SetTimer, % Timer, 1000
Return

CustomToolTip( text, x := "", y := "", title := ""
             , icon := 0  ; can be 1 — Info, 2 — Warning, 3 — Error, if greater than 3 — hIcon
             , closeButton := false, backColor := "", textColor := 0
             , fontName := "", fontOptions := ""  ; like in GUI
             , isBallon := false, timeout := "", maxWidth := 600 )
{
   static ttStyles := (TTS_NOPREFIX := 2) | (TTS_ALWAYSTIP := 1), TTS_BALLOON := 0x40, TTS_CLOSE := 0x80
        , TTF_TRACK := 0x20, TTF_ABSOLUTE := 0x80
        , TTM_SETMAXTIPWIDTH := 0x418, TTM_TRACKACTIVATE := 0x411, TTM_TRACKPOSITION := 0x412
        , TTM_SETTIPBKCOLOR := 0x413, TTM_SETTIPTEXTCOLOR := 0x414
        , TTM_ADDTOOL        := A_IsUnicode ? 0x432 : 0x404
        , TTM_SETTITLE       := A_IsUnicode ? 0x421 : 0x420
        , TTM_UPDATETIPTEXT  := A_IsUnicode ? 0x439 : 0x40C
        , exStyles := (WS_EX_TOPMOST := 0x00000008) | (WS_EX_COMPOSITED := 0x2000000) | (WS_EX_LAYERED := 0x80000)
        , WM_SETFONT := 0x30, WM_GETFONT := 0x31
   
   dhwPrev := A_DetectHiddenWindows, defGuiPrev := A_DefaultGui, lastFoundPrev := WinExist()
   DetectHiddenWindows, On
   hWnd := DllCall("CreateWindowEx", "UInt", exStyles, "Str", "tooltips_class32", "Str", ""
                                   , "UInt", ttStyles | TTS_CLOSE * !!CloseButton | TTS_BALLOON * !!isBallon
                                   , "Int", 0, "Int", 0, "Int", 0, "Int", 0, "Ptr", 0, "Ptr", 0, "Ptr", 0, "Ptr", 0, "Ptr")
   WinExist("ahk_id" . hWnd)
   if (textColor != 0 || backColor != "") {
      DllCall("UxTheme\SetWindowTheme", "Ptr", hWnd, "Ptr", 0, "UShortP", empty := 0)
      ByteSwap := Func("DllCall").Bind("msvcr100\_byteswap_ulong", "UInt")
      SendMessage, TTM_SETTIPBKCOLOR  , ByteSwap.Call(backColor << 8)
      SendMessage, TTM_SETTIPTEXTCOLOR, ByteSwap.Call(textColor << 8)
   }
   if (fontName || fontOptions) {
      Gui, New
      Gui, Font, % fontOptions, % fontName
      Gui, Add, Text, hwndhText
      SendMessage, WM_GETFONT,,,, ahk_id %hText%
      SendMessage, WM_SETFONT, ErrorLevel
      Gui, Destroy
      Gui, %defGuiPrev%: Default
   }
   VarSetCapacity(TOOLINFO, sz := 24 + A_PtrSize*6, 0)
   NumPut(sz, TOOLINFO)
   NumPut(TTF_TRACK | TTF_ABSOLUTE * !isBallon, TOOLINFO, 4)
   NumPut(&text, TOOLINFO, 24 + A_PtrSize*3)
   
   if (x = "" || y = "")
      DllCall("GetCursorPos", "Int64P", pt)
   (x = "" && x := (pt & 0xFFFFFFFF) + 15), (y = "" && y := (pt >> 32) + 15)
   
   SendMessage, TTM_SETTITLE      , icon, &title
   SendMessage, TTM_TRACKPOSITION ,     , x | (y << 16)
   SendMessage, TTM_SETMAXTIPWIDTH,     , maxWidth
   SendMessage, TTM_ADDTOOL       ,     , &TOOLINFO
   SendMessage, TTM_UPDATETIPTEXT ,     , &TOOLINFO
   SendMessage, TTM_TRACKACTIVATE , true, &TOOLINFO
   
   if timeout {
      Timer := Func("DllCall").Bind("DestroyWindow", "Ptr", hWnd)
      SetTimer, % Timer, % "-" . timeout
   }
   DetectHiddenWindows, % dhwPrev
   WinExist("ahk_id" . lastFoundPrev)
   Return hWnd
}

UpdateText(hTooltip, TextArray) {
   static TTM_UPDATETIPTEXT := A_IsUnicode ? 0x439 : 0x40C
   text := TextArray.Pop()
   VarSetCapacity(TOOLINFO, sz := 24 + A_PtrSize*6, 0)
   NumPut(sz, TOOLINFO)
   NumPut(&text, TOOLINFO, 24 + A_PtrSize*3)
   SendMessage, TTM_UPDATETIPTEXT,, &TOOLINFO,, ahk_id %hTooltip%
   if (TextArray[1] = "")
      SetTimer,, Delete
}
This is very nice. I am going to get heavy use out of it.

After a little testing, I determined that I will not use the timer. I will set the timeout to be a couple of minutes, and when I want to close the tooltip I will call it again with a timeout of 0.
Works great.
thanks
Check out my scripts. (MyIpChanger) (ClipBoard Manager) (SavePictureAs)
All my scripts are tested on Windows 10, AutoHotkey 32 bit Ansi unless otherwise stated.
teadrinker
Posts: 4330
Joined: 29 Mar 2015, 09:41
Contact:

Re: A bigger tooltip

12 Jan 2024, 05:03

DataLife wrote: Works great
Good to hear, here's a newer version (though written a few years ago):

Code: Select all

title := "Hello!"
text := "This is my custom TrayTip.`nIt will disappear in five seconds."

hToolTip := CustomToolTip({ title: title, text: text, icon: 1, closeButton: true
                          , backColor: 0xFFC141, textColor: 0x50669F, fontName: "Calibri"
                          , margin: [10, 10, 10, 10]
                          , trayTip: true
                          , fontOptions: "s18"
                          , timeout: 5000 }*)
                          
Timer := Func("UpdateText").Bind(hToolTip, [ StrReplace(text, "five seconds", "one second")
                                              , StrReplace(text, "five", "two")
                                              , StrReplace(text, "five", "three")
                                              , StrReplace(text, "five", "four") ])
SetTimer, % Timer, 1000
Sleep, 6000
ExitApp

CustomToolTip( text, x := "", y := "", title := ""
             , icon := 0  ; can be 1 — Info, 2 — Warning, 3 — Error, if greater than 3 — hIcon
             , transparent := false
             , margin := "" ; [left, top, right, bottom]
             , closeButton := false, backColor := 0xFFFFFF, textColor := 0
             , fontName := "", fontOptions := ""  ; like in GUI
             , trayTip := false
             , isBallon := false, timeout := "", maxWidth := 600 )
{
   static ttStyles := (TTS_NOPREFIX := 2) | (TTS_ALWAYSTIP := 1), TTS_BALLOON := 0x40, TTS_CLOSE := 0x80
        , TTF_TRACK := 0x20, TTF_ABSOLUTE := 0x80
        , TTM_SETMAXTIPWIDTH := 0x418, TTM_TRACKACTIVATE := 0x411, TTM_TRACKPOSITION := 0x412
        , TTM_SETTIPBKCOLOR := 0x413, TTM_SETTIPTEXTCOLOR := 0x414, TTM_SETMARGIN := 0x41A
        , TTM_ADDTOOL        := A_IsUnicode ? 0x432 : 0x404
        , TTM_SETTITLE       := A_IsUnicode ? 0x421 : 0x420
        , TTM_UPDATETIPTEXT  := A_IsUnicode ? 0x439 : 0x40C
        , WM_SETFONT := 0x30, WM_GETFONT := 0x31
        , WS_EX_TRANSPARENT := 0x00000020
        , exStyles := (WS_EX_TOPMOST := 0x00000008) | (WS_EX_COMPOSITED := 0x2000000) | (WS_EX_LAYERED := 0x00080000)
        
   dhwPrev := A_DetectHiddenWindows
   DetectHiddenWindows, On
   defGuiPrev := A_DefaultGui, lastFoundPrev := WinExist()
   (trayTip && isBallon := true)
   hWnd := DllCall("CreateWindowEx", "UInt", exStyles | WS_EX_TRANSPARENT * !!transparent, "Str", "tooltips_class32", "Str", ""
                                   , "UInt", ttStyles | TTS_CLOSE * !!CloseButton | TTS_BALLOON * !!isBallon
                                   , "Int", 0, "Int", 0, "Int", 0, "Int", 0, "Ptr", 0, "Ptr", 0, "Ptr", 0, "Ptr", 0, "Ptr")
   WinExist("ahk_id" . hWnd)
   DllCall("UxTheme\SetWindowTheme", "Ptr", hWnd, "Ptr", 0, "Str", "")
   SendMessage, TTM_SETTIPBKCOLOR  , backColor >> 16 | backColor & 0xFF00 | (backColor & 0xFF) << 16
   SendMessage, TTM_SETTIPTEXTCOLOR, textColor >> 16 | textColor & 0xFF00 | (textColor & 0xFF) << 16
   if (fontName || fontOptions) {
      Gui, New
      Gui, Font, % fontOptions, % fontName
      Gui, Add, Text, hwndhText
      SendMessage, WM_GETFONT,,,, ahk_id %hText%
      SendMessage, WM_SETFONT, ErrorLevel
      Gui, Destroy
      Gui, %defGuiPrev%: Default
   }
   if trayTip {
      Loc := GetTrayIconLocation()
      x := Loc.x + Loc.w//2
      y := Loc.y + 4
   }
   if (x = "" || y = "")
      DllCall("GetCursorPos", "Int64P", pt)
   (x = "" && x := (pt & 0xFFFFFFFF) + 15), (y = "" && y := (pt >> 32) + 15)
   
   if IsObject(margin) {
      VarSetCapacity(RECT, 16, 0)
      for k, v in margin
         NumPut(v, RECT, 4*(A_Index - 1), "UInt")
      SendMessage, TTM_SETMARGIN,, &RECT
   }
   
   VarSetCapacity(TOOLINFO, sz := 24 + A_PtrSize*6, 0)
   NumPut(sz, TOOLINFO)
   NumPut(TTF_TRACK | TTF_ABSOLUTE * !isBallon, TOOLINFO, 4)
   NumPut(&text, TOOLINFO, 24 + A_PtrSize*3)
   
   SendMessage, TTM_SETTITLE      , icon, &title
   SendMessage, TTM_TRACKPOSITION ,     , x | (y << 16)
   SendMessage, TTM_SETMAXTIPWIDTH,     , maxWidth
   SendMessage, TTM_ADDTOOL       ,     , &TOOLINFO
   SendMessage, TTM_UPDATETIPTEXT ,     , &TOOLINFO
   SendMessage, TTM_TRACKACTIVATE , true, &TOOLINFO
   
   if trayTip {
      timer := Func("TrackTrayIcon").Bind(hWnd)
      SetTimer, % timer, 300
   }
   
   if timeout {
      Timer := Func("DllCall").Bind("DestroyWindow", "Ptr", hWnd)
      SetTimer, % Timer, % "-" . timeout
   }
   WinExist("ahk_id" . lastFoundPrev)
   DetectHiddenWindows, % dhwPrev
   Return hWnd
}

UpdateText(hTooltip, TextArray) {
   static TTM_UPDATETIPTEXT := A_IsUnicode ? 0x439 : 0x40C
   text := TextArray.Pop()
   VarSetCapacity(TOOLINFO, sz := 24 + A_PtrSize*6, 0)
   NumPut(sz, TOOLINFO)
   NumPut(&text, TOOLINFO, 24 + A_PtrSize*3)
   SendMessage, TTM_UPDATETIPTEXT,, &TOOLINFO,, ahk_id %hTooltip%
   if (TextArray[1] = "")
      SetTimer,, Delete
}

TrackTrayIcon(hToolTip) {
   static x_prev := 0, y_prev := 0
   if !WinExist("ahk_id " . hToolTip) {
      SetTimer,, Delete
      Return
   }
   Loc := GetTrayIconLocation()
   x := Loc.x + Loc.w//2
   y := Loc.y + 4
   if (x != x_prev || y != y_prev) {
      SendMessage, TTM_TRACKPOSITION := 0x412,, x | (y << 16)
      x_prev := x, y_prev := y
   }
}

GetTrayIconLocation(hWnd := 0, uID := 0x404) {
   (!hWnd && hWnd := A_ScriptHwnd)
   VarSetCapacity(NOTIFYICONIDENTIFIER, structSize := A_PtrSize*3 + 16, 0)
   NumPut(structSize, NOTIFYICONIDENTIFIER)
   NumPut(hWnd, NOTIFYICONIDENTIFIER, A_PtrSize)
   NumPut(uID, NOTIFYICONIDENTIFIER, A_PtrSize*2)

   VarSetCapacity(RECT, 16, 0)
   hr := DllCall("Shell32\Shell_NotifyIconGetRect", "Ptr", &NOTIFYICONIDENTIFIER, "Ptr", &RECT)
   if (hr != 0)
      throw "Failed to get tray icon location"
   else {
      x := NumGet(RECT, "UInt")
      y := NumGet(RECT, 4, "UInt")
      w := NumGet(RECT, 8, "UInt") - x
      h := NumGet(RECT, 12, "UInt") - y
      Loc := {x: x, y: y, w: w, h: h}
   }
   Return Loc
}
User avatar
DataLife
Posts: 447
Joined: 29 Sep 2013, 19:52

Re: A bigger tooltip

12 Jan 2024, 15:09

teadrinker wrote:
12 Jan 2024, 05:03
DataLife wrote: Works great
Good to hear, here's a newer version (though written a few years ago):

Code: Select all

title := "Hello!"
text := "This is my custom TrayTip.`nIt will disappear in five seconds."

hToolTip := CustomToolTip({ title: title, text: text, icon: 1, closeButton: true
                          , backColor: 0xFFC141, textColor: 0x50669F, fontName: "Calibri"
                          , margin: [10, 10, 10, 10]
                          , trayTip: true
                          , fontOptions: "s18"
                          , timeout: 5000 }*)
                          
Timer := Func("UpdateText").Bind(hToolTip, [ StrReplace(text, "five seconds", "one second")
                                              , StrReplace(text, "five", "two")
                                              , StrReplace(text, "five", "three")
                                              , StrReplace(text, "five", "four") ])
SetTimer, % Timer, 1000
Sleep, 6000
ExitApp

CustomToolTip( text, x := "", y := "", title := ""
             , icon := 0  ; can be 1 — Info, 2 — Warning, 3 — Error, if greater than 3 — hIcon
             , transparent := false
             , margin := "" ; [left, top, right, bottom]
             , closeButton := false, backColor := 0xFFFFFF, textColor := 0
             , fontName := "", fontOptions := ""  ; like in GUI
             , trayTip := false
             , isBallon := false, timeout := "", maxWidth := 600 )
{
   static ttStyles := (TTS_NOPREFIX := 2) | (TTS_ALWAYSTIP := 1), TTS_BALLOON := 0x40, TTS_CLOSE := 0x80
        , TTF_TRACK := 0x20, TTF_ABSOLUTE := 0x80
        , TTM_SETMAXTIPWIDTH := 0x418, TTM_TRACKACTIVATE := 0x411, TTM_TRACKPOSITION := 0x412
        , TTM_SETTIPBKCOLOR := 0x413, TTM_SETTIPTEXTCOLOR := 0x414, TTM_SETMARGIN := 0x41A
        , TTM_ADDTOOL        := A_IsUnicode ? 0x432 : 0x404
        , TTM_SETTITLE       := A_IsUnicode ? 0x421 : 0x420
        , TTM_UPDATETIPTEXT  := A_IsUnicode ? 0x439 : 0x40C
        , WM_SETFONT := 0x30, WM_GETFONT := 0x31
        , WS_EX_TRANSPARENT := 0x00000020
        , exStyles := (WS_EX_TOPMOST := 0x00000008) | (WS_EX_COMPOSITED := 0x2000000) | (WS_EX_LAYERED := 0x00080000)
        
   dhwPrev := A_DetectHiddenWindows
   DetectHiddenWindows, On
   defGuiPrev := A_DefaultGui, lastFoundPrev := WinExist()
   (trayTip && isBallon := true)
   hWnd := DllCall("CreateWindowEx", "UInt", exStyles | WS_EX_TRANSPARENT * !!transparent, "Str", "tooltips_class32", "Str", ""
                                   , "UInt", ttStyles | TTS_CLOSE * !!CloseButton | TTS_BALLOON * !!isBallon
                                   , "Int", 0, "Int", 0, "Int", 0, "Int", 0, "Ptr", 0, "Ptr", 0, "Ptr", 0, "Ptr", 0, "Ptr")
   WinExist("ahk_id" . hWnd)
   DllCall("UxTheme\SetWindowTheme", "Ptr", hWnd, "Ptr", 0, "Str", "")
   SendMessage, TTM_SETTIPBKCOLOR  , backColor >> 16 | backColor & 0xFF00 | (backColor & 0xFF) << 16
   SendMessage, TTM_SETTIPTEXTCOLOR, textColor >> 16 | textColor & 0xFF00 | (textColor & 0xFF) << 16
   if (fontName || fontOptions) {
      Gui, New
      Gui, Font, % fontOptions, % fontName
      Gui, Add, Text, hwndhText
      SendMessage, WM_GETFONT,,,, ahk_id %hText%
      SendMessage, WM_SETFONT, ErrorLevel
      Gui, Destroy
      Gui, %defGuiPrev%: Default
   }
   if trayTip {
      Loc := GetTrayIconLocation()
      x := Loc.x + Loc.w//2
      y := Loc.y + 4
   }
   if (x = "" || y = "")
      DllCall("GetCursorPos", "Int64P", pt)
   (x = "" && x := (pt & 0xFFFFFFFF) + 15), (y = "" && y := (pt >> 32) + 15)
   
   if IsObject(margin) {
      VarSetCapacity(RECT, 16, 0)
      for k, v in margin
         NumPut(v, RECT, 4*(A_Index - 1), "UInt")
      SendMessage, TTM_SETMARGIN,, &RECT
   }
   
   VarSetCapacity(TOOLINFO, sz := 24 + A_PtrSize*6, 0)
   NumPut(sz, TOOLINFO)
   NumPut(TTF_TRACK | TTF_ABSOLUTE * !isBallon, TOOLINFO, 4)
   NumPut(&text, TOOLINFO, 24 + A_PtrSize*3)
   
   SendMessage, TTM_SETTITLE      , icon, &title
   SendMessage, TTM_TRACKPOSITION ,     , x | (y << 16)
   SendMessage, TTM_SETMAXTIPWIDTH,     , maxWidth
   SendMessage, TTM_ADDTOOL       ,     , &TOOLINFO
   SendMessage, TTM_UPDATETIPTEXT ,     , &TOOLINFO
   SendMessage, TTM_TRACKACTIVATE , true, &TOOLINFO
   
   if trayTip {
      timer := Func("TrackTrayIcon").Bind(hWnd)
      SetTimer, % timer, 300
   }
   
   if timeout {
      Timer := Func("DllCall").Bind("DestroyWindow", "Ptr", hWnd)
      SetTimer, % Timer, % "-" . timeout
   }
   WinExist("ahk_id" . lastFoundPrev)
   DetectHiddenWindows, % dhwPrev
   Return hWnd
}

UpdateText(hTooltip, TextArray) {
   static TTM_UPDATETIPTEXT := A_IsUnicode ? 0x439 : 0x40C
   text := TextArray.Pop()
   VarSetCapacity(TOOLINFO, sz := 24 + A_PtrSize*6, 0)
   NumPut(sz, TOOLINFO)
   NumPut(&text, TOOLINFO, 24 + A_PtrSize*3)
   SendMessage, TTM_UPDATETIPTEXT,, &TOOLINFO,, ahk_id %hTooltip%
   if (TextArray[1] = "")
      SetTimer,, Delete
}

TrackTrayIcon(hToolTip) {
   static x_prev := 0, y_prev := 0
   if !WinExist("ahk_id " . hToolTip) {
      SetTimer,, Delete
      Return
   }
   Loc := GetTrayIconLocation()
   x := Loc.x + Loc.w//2
   y := Loc.y + 4
   if (x != x_prev || y != y_prev) {
      SendMessage, TTM_TRACKPOSITION := 0x412,, x | (y << 16)
      x_prev := x, y_prev := y
   }
}

GetTrayIconLocation(hWnd := 0, uID := 0x404) {
   (!hWnd && hWnd := A_ScriptHwnd)
   VarSetCapacity(NOTIFYICONIDENTIFIER, structSize := A_PtrSize*3 + 16, 0)
   NumPut(structSize, NOTIFYICONIDENTIFIER)
   NumPut(hWnd, NOTIFYICONIDENTIFIER, A_PtrSize)
   NumPut(uID, NOTIFYICONIDENTIFIER, A_PtrSize*2)

   VarSetCapacity(RECT, 16, 0)
   hr := DllCall("Shell32\Shell_NotifyIconGetRect", "Ptr", &NOTIFYICONIDENTIFIER, "Ptr", &RECT)
   if (hr != 0)
      throw "Failed to get tray icon location"
   else {
      x := NumGet(RECT, "UInt")
      y := NumGet(RECT, 4, "UInt")
      w := NumGet(RECT, 8, "UInt") - x
      h := NumGet(RECT, 12, "UInt") - y
      Loc := {x: x, y: y, w: w, h: h}
   }
   Return Loc
}
Due to this function being variadic, I added x: 100 and y: 500 to the calling function parameters, to place the tooltip where I want it
I have alot to learn about functions.
It looks like the function call parameters don't match up with the function. They are out of order. How does that work?
Check out my scripts. (MyIpChanger) (ClipBoard Manager) (SavePictureAs)
All my scripts are tested on Windows 10, AutoHotkey 32 bit Ansi unless otherwise stated.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: mikeyww and 422 guests