Page 2 of 5

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

Posted: 06 Jul 2016, 23:07
by lexikos
@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.

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

Posted: 11 Jul 2016, 11:25
by arcticir
About TTM_SETMAXTIPWIDTH, Can you provide an example? :)

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

Posted: 11 Jul 2016, 22:15
by lexikos
No.

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

Posted: 11 Jul 2016, 22:59
by joedf
@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%
}

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

Posted: 11 Jul 2016, 23:18
by arcticir
Joedf, thanks. I use a different method, solved the problem.

https://autohotkey.com/boards/viewtopic ... 28&t=20192

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

Posted: 01 Nov 2016, 12:11
by rommmcek
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?

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

Posted: 01 Nov 2016, 14:09
by Relayer
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

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

Posted: 28 Jan 2017, 09:14
by rommmcek
@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.

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

Posted: 04 Feb 2017, 08:01
by rommmcek
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!

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

Posted: 02 Dec 2017, 11:21
by rommmcek
After almost one year using ToolTipFont for ToolTipAll now I switched to Fnt library! It shouldn't affect other processes and is more reliable.

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

Posted: 04 Mar 2018, 13:52
by chegr
I'd expected to see this natively in v2, but nope! I'll try to get it working...

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

Posted: 04 Mar 2018, 14:03
by Flipeador
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

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

Posted: 27 Jul 2018, 21:14
by Gris
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?

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

Posted: 02 Aug 2018, 13:11
by joedf
The example script provided here is a good place to start :+1:
https://autohotkey.com/boards/viewtopic ... 472#p27472

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

Posted: 15 Aug 2018, 18:23
by drozdman
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
	

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

Posted: 17 Aug 2018, 07:50
by joedf
How fast are you pressing Ctrl+G between each interval?

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

Posted: 17 Aug 2018, 09:59
by drozdman
@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.

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

Posted: 18 Aug 2018, 08:41
by ahk7
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.

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

Posted: 18 Aug 2018, 11:26
by burque505
@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

Re: ToolTipFont / ToolTipColor - options for the ToolTip command

Posted: 18 Aug 2018, 12:38
by Flipeador
@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: