ToolTipFont / ToolTipColor - options for the ToolTip command

Post your working scripts, libraries and tools for AHK v1.1 and older
lexikos
Posts: 9494
Joined: 30 Sep 2013, 04:07
Contact:

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

06 Jul 2016, 23:07

@arcticir: Probably with TTM_SETMAXTIPWIDTH.

@rommmcek: Thanks for reporting the bug; I've fixed it.

I suppose you can simply use WinGetPos to get the dimensions of the tooltip.
arcticir
Posts: 693
Joined: 17 Nov 2013, 11:32

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

11 Jul 2016, 11:25

About TTM_SETMAXTIPWIDTH, Can you provide an example? :)
User avatar
joedf
Posts: 8937
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

11 Jul 2016, 22:59

@arcticir Try this? untested. :)

Code: Select all

TT_SetMaxWidth(MaxWidth := -1, hwnd := "") {
	; see https://msdn.microsoft.com/library/bb760408
	WM_USER := 1024
	TTM_SETMAXTIPWIDTH := (WM_USER+24)
	SendMessage, %TTM_SETMAXTIPWIDTH%, 0, %MaxWidth%, , ahk_id %hwnd%
	return %ErrorLevel%
}
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
User avatar
rommmcek
Posts: 1470
Joined: 15 Aug 2014, 15:18

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

01 Nov 2016, 12:11

It seems that I solved occasional broken display reported 07/06/16.
I use sleep, 0 or sleep, -1 before return DllCall("CallNextHookEx", "ptr", 0, "int", nCode, "ptr", _wp, "ptr", _lp, "ptr")

P.s.: Obviously I missed your answer:
I suppose you can simply use WinGetPos to get the dimensions of the tooltip.
Yes, this is after displaying! What about beforehand?
User avatar
Relayer
Posts: 160
Joined: 30 Sep 2013, 13:09
Location: Delaware, USA

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

01 Nov 2016, 14:09

Yes, this is after displaying! What about beforehand?
I have been using the Fnt library for this. It has functions that return size given the text you want to display. https://autohotkey.com/boards/viewtopic.php?t=4379

Relayer
User avatar
rommmcek
Posts: 1470
Joined: 15 Aug 2014, 15:18

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

28 Jan 2017, 09:14

@Relayer: Thanks, after initial trouble I started to like it! I even made a small contribution: https://autohotkey.com/boards/viewtopic ... 31#p128531

@lexikos: As much as I like ToolTipFont for it's simplicity to update old scripts, it seems that it's suitable only for simple code.
I've isolated three issues I encountered, two of them easily to reproduce!

Code: Select all

#NoEnv
#Warn
#SingleInstance Force
SetWorkingDir %A_ScriptDir%
#include, TooltipFont.ahk
;~ #include, Fnt.ahk

ToolTipFont("s32", "Magneto")
ToolTipColor("c0ffc0", "800080")

EText := "Madrugada"

Gui, font, s14
Gui, Add, Edit, xm w175
Gui, Add, Button, y+m gBLabel, Show ToolTipFont
Gui, Show, x300, Window
ControlSend,, {Tab}, Window ahk_class AutoHotkeyGUI
Return

GuiEscape:
GuiClose:
    ExitApp
return

BLabel:
;gui Submit,NoHide
ControlSetText, Edit1, % "", Window ahk_class AutoHotkeyGUI   ;works
ToolTip, Hello ToolTipFont!, -250, 345
;~ ToolTipFnt("s32", "Magneto")
sleep, 1000
Msgbox Cancel_ToolTipFont & Set_Text`nTo Edit_Control !
Clipboard:=""
Clipboard:=EText
ClipWait
;ToolTip
;sleep, 500
;~ SendMessage, 0xC, , "Anochecer", Edit1, Window ahk_class AutoHotkeyGUI   ;doesn't work
SendMessage, 0xC, , &EText, Edit1, Window ahk_class AutoHotkeyGUI   ;doesn't work
;~ ControlSetText, Edit1, % EText, Window ahk_class AutoHotkeyGUI   ;works
Sleep, 500
   ToolTip
return

exitapp

1. SendMessage inhibited.
2. Assigning to Clipboard make the script crash.
---------------------------
Limitations 4 TTF.ahk
---------------------------
Error in #include file "TooltipFont 1.005.ahk":
SetClipboardData

059: } Sleep,- 1
---> 060: Return,DllCall("CallNextHookEx", "ptr", 0, "int", nCode, "ptr", _wp, "ptr", _lp, "ptr")
061: }

The current thread will exit.
---------------------------
OK
---------------------------
3. Dialogs display blank if mouse cursor is off field where they appear or off field of script's Gui if visible (not allways reproducible, see pic.)

P.s.: These issues don't appear if running ToolTipFont functions from another script, however simplicity is obviously lost.
Attachments
Limitations 4 TTF.png
Limitations 4 TTF.png (90.72 KiB) Viewed 10889 times
Last edited by rommmcek on 04 Feb 2017, 08:05, edited 1 time in total.
User avatar
rommmcek
Posts: 1470
Joined: 15 Aug 2014, 15:18

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

04 Feb 2017, 08:01

I just had a surreal idea, what about Third Part Application ToolTips?
Using Serenity's functions & this very handy ToolTipFont by lexikos I got some success, however ToolTips in Explorers Control DirectUIHWND3 are updated only if triggering of the next ToolTip (form the same Control) occurs in less then circa 300 ms after pervious one (being still displayed).

Code: Select all

#NoEnv
#SingleInstance Force
#Persistent
DetectHiddenWindows, On
DetectHiddenText, On

ToolTipFont("s16")

HookProcAdr := RegisterCallback( "HookProc", "F" )
hWinEventHook := SetWinEventHook( 0x8000, 0x8003, 0, HookProcAdr, 0, 0, 0 ) ; create, destroy, show and hide events 
Return

#Include, C:\Users\RRR\My Ahk-s\ToolTipFont.ahk

HookProc( hWinEventHook, Event, hWnd, idObject, idChild, dwEventThread, dwmsEventTime )
{  
	if Event 
	{
		WinGetClass, class, ahk_id %hWnd%
		If (class = "tooltips_class32")
					ToolTipFont(,, hwnd)
	}
}

SetWinEventHook(eventMin, eventMax, hmodWinEventProc, lpfnWinEventProc, idProcess, idThread, dwFlags)
{
	DllCall("CoInitialize", Uint, 0)
	return DllCall("SetWinEventHook"
	, Uint,eventMin	
	, Uint,eventMax	
	, Uint,hmodWinEventProc
	, Uint,lpfnWinEventProc
	, Uint,idProcess
	, Uint,idThread
	, Uint,dwFlags)	
}

UnhookWinEvent()
{
	Global
	DllCall( "UnhookWinEvent", Uint,hWinEventHook )
	DllCall( "GlobalFree", UInt,&HookProcAdr ) ; free up allocated memory for RegisterCallback
}

+Esc::
HandleExit:
UnhookWinEvent()
ExitApp
Return

!F2::
SoundBeep, 800, 300
UnhookWinEvent()
Reload
return
P.s.: Any improvements are appreciated!
Attachments
ToolTipAll.png
ToolTipAll.png (50.55 KiB) Viewed 10790 times
User avatar
rommmcek
Posts: 1470
Joined: 15 Aug 2014, 15:18

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

02 Dec 2017, 11:21

After almost one year using ToolTipFont for ToolTipAll now I switched to Fnt library! It shouldn't affect other processes and is more reliable.
chegr
Posts: 13
Joined: 04 Feb 2018, 09:36

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

04 Mar 2018, 13:52

I'd expected to see this natively in v2, but nope! I'll try to get it working...
User avatar
Flipeador
Posts: 1204
Joined: 15 Nov 2014, 21:31
Location: Argentina
Contact:

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

04 Mar 2018, 14:03

chegr wrote:I'd expected to see this natively in v2, but nope! I'll try to get it working...
I have a ToolTip class for AHK v2, maybe you're interested, it's in the forum in Spanish but it includes an example. Personally I think it should be implemented natively in the versión 2. I created this class based on GuiControlTips by just me, all credits for him..
https://github.com/flipeador/Library-Au ... oolTip.ahk
Gris

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

27 Jul 2018, 21:14

Just starting to learn AHK. How do I use this script? Do I compile the code and then put ToolTipColor("Black", "White") in my script?
Tried that and it didn't work. Any suggestions?
drozdman
Posts: 78
Joined: 05 Dec 2015, 01:07

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

15 Aug 2018, 18:23

This has been working well, but recently I tried to use it with this script Sets of hotkeys and I got SetClipboardData error.

Like in this test script. Try using Ctrl+G several times for copying text.

Code: Select all

#SingleInstance force

/* 
	Error:  SetClipboardData
--->	076: Return,DllCall("CallNextHookEx", "ptr", 0, "int", nCode, "ptr", _wp, "ptr", _lp, "ptr")
 */
 
	ToolTipFont("s9 w400", "Tahoma")
	ToolTipColor("FAFAEE", "000000")

return

~^g:: Gosub, test


test:
	last_clipboard = %clipboard% 
	last_clipboard:=Trim(last_clipboard)
	Send, ^c 	
	clipboard:=Trim(clipboard)
	clipboard = %last_clipboard%` %clipboard% 

	ToolTip, % clipboard
return
 
ToolTipFont(Options := "", Name := "", hwnd := ""){ ;lexikos https://autohotkey.com/boards/viewtopic.php?t=4777
    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")
}
 ; error SetClipboardData
 
_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
    }
}



Close:
Esc:: 
ExitApp
	
User avatar
joedf
Posts: 8937
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

17 Aug 2018, 07:50

How fast are you pressing Ctrl+G between each interval?
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
drozdman
Posts: 78
Joined: 05 Dec 2015, 01:07

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

17 Aug 2018, 09:59

@joedf
It doesn't have to be fast. I just select some text and press the hotkey, then another text and so on (a few seconds between).
Sometimes it happens with the first hotkey.

So other people don't experience this? I tried to run it without other scripts running, but it still happens.
ahk7
Posts: 572
Joined: 06 Nov 2013, 16:35

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

18 Aug 2018, 08:41

I get that error too - I tried to add this to my CL3 clipboard script for the "cycle through history" tooltips but when releasing the key that would assign the chosen text to the clipboard and paste it this error shows up.
burque505
Posts: 1731
Joined: 22 Jan 2017, 19:37

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

18 Aug 2018, 11:26

@flipeador, thanks for that class! Here's a first shot at a translation into English. If you get a chance to make sure it's at least close to correct, I'd really appreciate it.
Spoiler
Regards,
burque505
User avatar
Flipeador
Posts: 1204
Joined: 15 Nov 2014, 21:31
Location: Argentina
Contact:

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

18 Aug 2018, 12:38

@burque505 Looks good. Anyway I'm not good at writing documentation, I'm always discontent and I rewrite everything (the same happens to me with the coding style). :lolno: :lol: :facepalm:
:wave:

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: JoeWinograd and 77 guests