Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

[AHL_L/v2] TT() - Full-blown ToolTip Library


  • Please log in to reply
197 replies to this topic
Solar
  • Members
  • 345 posts
  • Last active: Jan 15 2012 08:11 PM
  • Joined: 03 May 2009
First: not a bug but you have 2 bitOR 16 statements when only one is needed.

Second: The bug that will likely break scripts if you fix it. You have ParseLinks as a default for ToolTip.Add() when no options are passed. The reason why this is a bug? Well, 2 reasons:

1. There's no way to disable it without setting some other option. Users may want to send text containing <a> literally.
2. If user is using HWND as an option, ParseLinks becomes disabled by default. Which is the opposite of the ClassNN's default usage.

These 2 issues are highlighted in red:

TT_ADD(T,Control,Text="",uFlags="",Parent=""){
	;	uFlags http://msdn.microsoft.com/en-us/library/bb760256.aspx
	; TTF_ABSOLUTE=0x80, TTF_CENTERTIP=0x0002, TTF_IDISHWND=0x1, TTF_PARSELINKS=0x1000 ,TTF_RTLREADING = 0x4
	; TTF_SUBCLASS=0x10, TTF_TRACK=0x20, TTF_TRANSPARENT=0x100
	static TOOLINFO="cbSize,uFlags,UPTR hwnd,UPTR uId,RECT rect,UPTR hinst,LPTSTR lpszText,UPTR lParam,void *lpReserved"
	DetectHiddenWindows:=A_DetectHiddenWindows
	DetectHiddenWindows,On
	if (Parent){
		If (Parent && Parent<100 and !DllCall("IsWindow","UPTR",Parent)){
			Gui %Parent%:+LastFound
			Parent:=WinExist()
		}
		T["T",Abs(Parent)]:=Struct(TOOLINFO),Tool:=T["T",Abs(Parent)]
		Tool.uId:=Parent,Tool.hwnd:=Parent,Tool.uFlags:=(0|16)
		DllCall("GetClientRect","UPTR",T.HWND,"UPTR", T[Abs(Parent)].rect[])
		T.ADDTOOL(T["T",Abs(Parent)][])
	}
	If text=
		ControlGetText,text,%Control%,% "ahk_id " (Parent?Parent:T.P.hwnd)
	If Control is not Xdigit
		If Control is not digit
			ControlGet,Control,Hwnd,,%Control%,% "ahk_id " (Parent?Parent:T.P.hwnd)
	If uFlags
		If uFlags is not digit
		{
			Loop,Parse,uflags,%A_Space%,%A_Space%
				If A_LoopField
					%A_LoopField% := 1
			uFlags:=(HWND?0x1:HWND=""?0x1:0)|(Center?0x2:0)|(RTL?0x4:0)|(SUB?0x10:0)|(Track?0x20:0)|(Absolute?0x80:0)|(TRANSPARENT?0x100:0)|(ParseLinks?0x1000:0)[color=red]|16[/color]
		}
	T["T",Abs(Control)]:=Struct(TOOLINFO)
	Tool:=T.T[Abs(Control)]
	Tool.cbSize:=Struct(Tool)
	T[Abs(Control),"text"]:=RegExReplace(text,"<a\K[^<]*?>",">")
	Tool.uId:=Control,Tool.hwnd:=Parent?Parent:T.P.hwnd,Tool.uFlags:=uFlags?(uFlags|16):(1[color=red]|0x1000[/color]|16)
	Tool.lpszText:=T[Abs(Control)].GetAddress("text")
	DllCall("GetClientRect","UPTR",T.HWND,"UPTR",Tool.rect[])
	T.ADDTOOL(Tool[])
	DetectHiddenWindows,%DetectHiddenWindows%
}
Example:
#Include struct.ahk
#Include tt.ahk

TT := TT("")
Gui, Add, Button, HWNDhButton1, Button1

TT.Add("Button1", "<a>link</a>") ; link will be parsed
;TT.Add("Button1", "<a>link</a>", 0) ; link will be unparsed. sending 0 as option for workaround.

;TT.Add(hButton1, "<a>link</a>", "HWND PARSELINKS") ; link will be parsed. requires parselinks
;TT.Add(hButton1, "<a>link</a>", "HWND") ; link will be unparsed.

Gui, Show
return

GuiEscape:
GuiClose:
	ExitApp


HotKeyIt
  • Moderators
  • 7439 posts
  • Last active: Jun 22 2016 09:14 PM
  • Joined: 18 Jun 2008

Add 0x100 to the static's Gui control options to enable the SS_NOTIFY style. You might want to include this in the documentation.

Thanks ;)

First: not a bug but you have 2 bitOR 16 statements when only one is needed.

Second: The bug that will likely break scripts if you fix it. You have ParseLinks as a default for ToolTip.Add() when no options are passed.

Thanks, this is fixed.

Solar
  • Members
  • 345 posts
  • Last active: Jan 15 2012 08:11 PM
  • Joined: 03 May 2009
Since the fix in the last post changed TT.Add behavior, you'll want to add the ParseLinks option for example 3:

TT.Add("Button1","<a>You can't click me :)</a>"[color=green], "ParseLinks"[/color])
Also, about the SetFormat, Integer issue a few posts back, is this a known issue with Struct()?

The reason why it was so hard to debug is:

If the slow mode "Integer" or "Float" is used anywhere in the script, even if that SetFormat line is never executed, the caching of integers or floating point numbers (respectively) is disabled the moment the script launches.

I wouldn't mind if this doesn't get fixed as I see no reason that it needs to be. However, you should probably include a notice on the Struct() thread or documentation.

HotKeyIt
  • Moderators
  • 7439 posts
  • Last active: Jun 22 2016 09:14 PM
  • Joined: 18 Jun 2008

Since the fix in the last post changed TT.Add behavior, you'll want to add the ParseLinks option for example 3:

Thanks, I've added it.

Also, about the SetFormat, Integer issue a few posts back, is this a known issue with Struct()?

Can you give an example, I could not reproduce it :?

Solar
  • Members
  • 345 posts
  • Last active: Jan 15 2012 08:11 PM
  • Joined: 03 May 2009

Can you give an example, I could not reproduce it :?

Really? I posted a perfect example a few posts back. Here it is again:

#Include struct.ahk 
#Include tt.ahk 

SetFormat, Integer, D 
;SetFormat, Integer, H ; or this 

TT := TT("","text here","title here") 
TT.Show()
This displays the pointer to the string instead of "text here".

HotKeyIt
  • Moderators
  • 7439 posts
  • Last active: Jun 22 2016 09:14 PM
  • Joined: 18 Jun 2008
Sorry about that, I have fixed Struct.ahk long ago but looks like forgot to upload :oops:
Redownload Struct.ahk

Solar
  • Members
  • 345 posts
  • Last active: Jan 15 2012 08:11 PM
  • Joined: 03 May 2009

Redownload Struct.ahk

That worked. Thank you.

Question about TT.Add(): After the tooltip has displayed, is it possible to have the tooltip remain open after moving the mouse off of the control? A good example of this is in example3 of your original post. It shows a link in the tooltip but you are unable to click it because moving the cursor off of the control would cause the tooltip to close.

HotKeyIt
  • Moderators
  • 7439 posts
  • Last active: Jun 22 2016 09:14 PM
  • Joined: 18 Jun 2008
The only way I can think of is to display your own message.
TT:=TT("OnClick=TTClick ClickHide OnShow=TTShow OnClose=TTHide ParseLinks")

Gui,Add,Edit,,I'm an Edit Box

TT.Add("Edit1")

Gui,Add,Button,,I'm a Button

TT.Add("Button1")

Gui,Show

Return

GuiClose:

Gui,Destroy

TT_Remove() ;remove all tooltips

ExitApp

TTClick(what){

  MsgBox % what

}

TTShow(){

  Global TT

  static Edit1:="Hello click me",Button1:="Click me too"

  MouseGetPos,,,win,control

  ControlGetPos,x,y,w,h,%control%,ahk_id %win%

  WinGetPos,wx,wy,ww,wh,ahk_id %win%

  text:=%control%

  TT.Show("<a>" text "</a>",wx+x,wy+y+h)

}


zeus19
  • Members
  • 49 posts
  • Last active: Feb 24 2017 12:59 PM
  • Joined: 14 Apr 2011
the tt.show, is it worked with win7 x64? (With coordinate app position)

HotKeyIt
  • Moderators
  • 7439 posts
  • Last active: Jun 22 2016 09:14 PM
  • Joined: 18 Jun 2008
I don't have a 64-bit machine but some time ago I tested it and it worked.

  • Guests
  • Last active:
  • Joined: --
my code using the library doesn't work anymore in the sense tooltips don't show, though no error messages neither.

Solar
  • Members
  • 345 posts
  • Last active: Jan 15 2012 08:11 PM
  • Joined: 03 May 2009

my code using the library doesn't work anymore in the sense tooltips don't show, though no error messages neither.

Post your code or reproduce the problem into a small script example.

segalion
  • Members
  • 50 posts
  • Last active: Oct 16 2014 09:20 AM
  • Joined: 02 Feb 2011

Thanks dysmas, I will take a look.

But I dont have skills to do that...
Could be great to have w and h options for the icon... in TT funtion.

Thanks a lot.

Here is an example how you could load a picture onto ToolTip using AniGif, shajul kindly converted to AHK_L
TT:=TT()
 TT.SetMargin(100)
 gHwnd:=AniGif_CreateControl(TT.hwnd, 0, 0, 100, 100)
 WideCharToMultiByte("hal-1.gif",sFile)
 AniGif_LoadGifFromFile(gHwnd,sFile)
 TT.Show("Hello","","","AutoHotkey")
 MsgBox Exiting now
 Exitapp



Thanks a lot, HotKeyIt

Ive tested (on ansi) and work fine!!!.

Sadly, I need .png and other image formats... This is to show a photo, that can be multiformat, multisize, ... Any recomendation?

DHMH
  • Members
  • 230 posts
  • Last active: Mar 25 2012 10:34 AM
  • Joined: 17 Jul 2008
HotkeyIt, please fix this:
Posted Image
Thanks!

HotKeyIt
  • Moderators
  • 7439 posts
  • Last active: Jun 22 2016 09:14 PM
  • Joined: 18 Jun 2008
Thanks for letting me know, I thought I have already updated it :oops:
You can download now.