AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Add ToolTips to controls.
Goto page Previous  1, 2, 3  Next
 
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
HotKeyIt



Joined: 18 Jun 2008
Posts: 4648
Location: AHK Forum

PostPosted: Tue May 12, 2009 12:59 pm    Post subject: Reply with quote

Hi Superfraggle, we've got one small issue/problem.

If only 1 Control is associated with ToolTip, ToolTip will not pop up again after it has been hidden by system (not by mouse movements)

Any ideas?
Code:

; ### Example Code #####
Gui,Add,Button,hwndbutton1,Test Button 1
AddTooltip(button1,"Press me to change my tooltip")
Gui,show,,Test Gui
Return
GuiClose:
Guiescape:
Exitapp

; ### End Example Code #####

AddToolTip(con,text,Modify = 0){
  Static TThwnd,GuiHwnd
  If (!TThwnd){
    Gui,+LastFound
    GuiHwnd:=WinExist()
    TThwnd:=CreateTooltipControl(GuiHwnd)
  }
  Varsetcapacity(TInfo,44,0)
  Numput(44,TInfo)
  Numput(1|16,TInfo,4)
  Numput(GuiHwnd,TInfo,8)
  Numput(con,TInfo,12)
  Numput(&text,TInfo,36)
  Detecthiddenwindows,on
  If (Modify){
    SendMessage,1036,0,&TInfo,,ahk_id %TThwnd%
  }
  Else {
    Sendmessage,1028,0,&TInfo,,ahk_id %TThwnd%
    SendMessage,1048,0,300,,ahk_id %TThwnd%
  }
 
}

CreateTooltipControl(hwind){
  Ret:=DllCall("CreateWindowEx"
          ,"Uint",0
          ,"Str","TOOLTIPS_CLASS32"
          ,"Uint",0
          ,"Uint",2147483648 | 3
          ,"Uint",-2147483648
          ,"Uint",-2147483648
          ,"Uint",-2147483648
          ,"Uint",-2147483648
          ,"Uint",hwind
          ,"Uint",0
          ,"Uint",0
          ,"Uint",0)
         
  Return Ret
}

_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun Wink
Back to top
View user's profile Send private message
Tilex



Joined: 01 Jun 2009
Posts: 5
Location: Germany

PostPosted: Mon Jun 01, 2009 8:05 pm    Post subject: Reply with quote

first to say: thanks for that feature Smile

but I have one problem:
I want to set a tooltip for an edit-box, which is disabled.
How do I do that? It only shows the tooltip, when it is enabled again.


bye,
Tilex
Back to top
View user's profile Send private message
Superfraggle



Joined: 02 Nov 2004
Posts: 1019
Location: London, UK

PostPosted: Thu Jun 04, 2009 9:20 pm    Post subject: Reply with quote

HotKeyIt,

Sorry about the delay in getting back to you, I have not been on the forum for a while. Not sure what you mean there.
If you mean let the tooltip close itself, then move mouse to bring it back. If I move the mouse off the control and back on the tooltip reappears.

I am on vista, so that could be an XP bug.

Tilex,

I believe that is standard windows and cannot be bypassed, you would have to write custom tooltips as suggested in the manual.
_________________
Steve F AKA Superfraggle

http://r.yuwie.com/superfraggle
Back to top
View user's profile Send private message MSN Messenger
HotKeyIt



Joined: 18 Jun 2008
Posts: 4648
Location: AHK Forum

PostPosted: Thu Jun 04, 2009 9:36 pm    Post subject: Reply with quote

Superfraggle wrote:
HotKeyIt,

Sorry about the delay in getting back to you, I have not been on the forum for a while. Not sure what you mean there.
If you mean let the tooltip close itself, then move mouse to bring it back. If I move the mouse off the control and back on the tooltip reappears.

I am on vista, so that could be an XP bug.


Try this, do not move your mouse until the ToolTip disappears and it will not come back.
I fixed this already in ToolTip() by adding a tool for Gui hWnd, give it a try, many thanks to you.
Code:


; ### Example Code #####
Gui,Add,Button,hwndbutton1 Gbut1,Test Button 1
AddTooltip(button1,"Press me to change my tooltip")
Gui,show,,Test Gui
Return

But1:
AddTooltip(button1,"Wasn't that easy `;)",1)
REturn

GuiClose:
Guiescape:
Exitapp

; ### End Example Code #####

AddToolTip(con,text,Modify = 0){
  Static TThwnd,GuiHwnd
  If (!TThwnd){
    Gui,+LastFound
    GuiHwnd:=WinExist()
    TThwnd:=CreateTooltipControl(GuiHwnd)
  }
  Varsetcapacity(TInfo,44,0)
  Numput(44,TInfo)
  Numput(1|16,TInfo,4)
  Numput(GuiHwnd,TInfo,8)
  Numput(con,TInfo,12)
  Numput(&text,TInfo,36)
  Detecthiddenwindows,on
  If (Modify){
    SendMessage,1036,0,&TInfo,,ahk_id %TThwnd%
  }
  Else {
    Sendmessage,1028,0,&TInfo,,ahk_id %TThwnd%
    SendMessage,1048,0,300,,ahk_id %TThwnd%
  }
 
}

CreateTooltipControl(hwind){
  Ret:=DllCall("CreateWindowEx"
          ,"Uint",0
          ,"Str","TOOLTIPS_CLASS32"
          ,"Uint",0
          ,"Uint",2147483648 | 3
          ,"Uint",-2147483648
          ,"Uint",-2147483648
          ,"Uint",-2147483648
          ,"Uint",-2147483648
          ,"Uint",hwind
          ,"Uint",0
          ,"Uint",0
          ,"Uint",0)
         
  Return Ret
}


Fix for your function:
Code:


; ### Example Code #####
Gui,Add,Button,hwndbutton1 Gbut1,Test Button 1
AddTooltip(button1,"Press me to change my tooltip")
Gui,show,,Test Gui
Return

But1:
AddTooltip(button1,"Wasn't that easy `;)",1)
REturn

GuiClose:
Guiescape:
Exitapp

; ### End Example Code #####

AddToolTip(con,text,Modify = 0){
  Static TThwnd,GuiHwnd
  If (!TThwnd){
    Gui,+LastFound
    GuiHwnd:=WinExist()
    TThwnd:=CreateTooltipControl(GuiHwnd)
   Varsetcapacity(TInfo,44,0)
   Numput(44,TInfo)
   Numput(1|16,TInfo,4)
   Numput(GuiHwnd,TInfo,8)
   Numput(GuiHwnd,TInfo,12)
   ;Numput(&text,TInfo,36)
   Detecthiddenwindows,on
   Sendmessage,1028,0,&TInfo,,ahk_id %TThwnd%
    SendMessage,1048,0,300,,ahk_id %TThwnd%
  }
  Varsetcapacity(TInfo,44,0)
  Numput(44,TInfo)
  Numput(1|16,TInfo,4)
  Numput(GuiHwnd,TInfo,8)
  Numput(con,TInfo,12)
  Numput(&text,TInfo,36)
  Detecthiddenwindows,on
  If (Modify){
    SendMessage,1036,0,&TInfo,,ahk_id %TThwnd%
  }
  Else {
    Sendmessage,1028,0,&TInfo,,ahk_id %TThwnd%
    SendMessage,1048,0,300,,ahk_id %TThwnd%
  }
 
}

CreateTooltipControl(hwind){
  Ret:=DllCall("CreateWindowEx"
          ,"Uint",0
          ,"Str","TOOLTIPS_CLASS32"
          ,"Uint",0
          ,"Uint",2147483648 | 3
          ,"Uint",-2147483648
          ,"Uint",-2147483648
          ,"Uint",-2147483648
          ,"Uint",-2147483648
          ,"Uint",hwind
          ,"Uint",0
          ,"Uint",0
          ,"Uint",0)
         
  Return Ret
}

_________________
AHK_H (2alpha) AHF TT _Struct WatchDir Yaml _Input ObjTree RapidHotkey DynaRun Wink
Back to top
View user's profile Send private message
fragman



Joined: 13 Oct 2009
Posts: 1191

PostPosted: Sat May 14, 2011 12:40 pm    Post subject: Reply with quote

Here's a working version for AHK_L Unicode (x64 untested so far, but should work)
Code:
AddToolTip(con,text,Modify = 0)
{
   Static TThwnd,GuiHwnd
   l_DetectHiddenWindows:=A_DetectHiddenWindows
   If (!TThwnd)
   {
      Gui,+LastFound
      GuiHwnd:=WinExist()
      TThwnd:=CreateTooltipControl(GuiHwnd)
      Varsetcapacity(TInfo,6*4+6*A_PtrSize,0)
      Numput(6*4+6*A_PtrSize,TInfo, "UInt")
      Numput(1|16,TInfo,4, "UInt")
      Numput(GuiHwnd,TInfo,8, "PTR")
      Numput(GuiHwnd,TInfo,8+A_PtrSize, "PTR")
      ;Numput(&text,TInfo,36)
      Detecthiddenwindows,on
      Sendmessage,1028,0,&TInfo,,ahk_id %TThwnd%
      SendMessage,1048,0,300,,ahk_id %TThwnd%
   }
   Varsetcapacity(TInfo,6*4+6*A_PtrSize,0)
   Numput(6*4+6*A_PtrSize,TInfo, "UInt")
   Numput(1|16,TInfo,4, "UInt")
   Numput(GuiHwnd,TInfo,8, "PTR")
   Numput(con,TInfo,8+A_PtrSize, "PTR")
   VarSetCapacity(ANSItext, StrPut(text, ""))
    StrPut(text, &ANSItext, "")
   Numput(&ANSIText,TInfo,6*4+3*A_PtrSize, "PTR")

   Detecthiddenwindows,on
   If (Modify)
      SendMessage,1036,0,&TInfo,,ahk_id %TThwnd%
   Else {
      Sendmessage,1028,0,&TInfo,,ahk_id %TThwnd%
      SendMessage,1048,0,300,,ahk_id %TThwnd%
   }
   DetectHiddenWindows %l_DetectHiddenWindows%
}
CreateTooltipControl(hwind)
{
   Ret:=DllCall("CreateWindowEx"
   ,"Uint",0
   ,"Str","TOOLTIPS_CLASS32"
   ,"PTR",0
   ,"Uint",2147483648 | 3
   ,"Uint",-2147483648
   ,"Uint",-2147483648
   ,"Uint",-2147483648
   ,"Uint",-2147483648
   ,"PTR",hwind
   ,"PTR",0
   ,"PTR",0
   ,"PTR",0, "PTR")
   Return Ret
}
Back to top
View user's profile Send private message
uni guest
Guest





PostPosted: Sat May 28, 2011 12:06 pm    Post subject: Reply with quote

fragman, your version doesn't work for unicode characters. Tested on AHK_L 1.1.00.00 unicode. Can you fix it? Test:
Code:
Gui,Add,Button,hwndbutton1, Test Button 1
AddTooltip(button1,"Ж.И.`nЮ.Щ.")
Gui,show,,Test Gui
Return

GuiClose:
Exitapp

AddToolTip(con,text,Modify = 0)
{
   Static TThwnd,GuiHwnd
   l_DetectHiddenWindows:=A_DetectHiddenWindows
   If (!TThwnd)
   {
      Gui,+LastFound
      GuiHwnd:=WinExist()
      TThwnd:=CreateTooltipControl(GuiHwnd)
      Varsetcapacity(TInfo,6*4+6*A_PtrSize,0)
      Numput(6*4+6*A_PtrSize,TInfo, "UInt")
      Numput(1|16,TInfo,4, "UInt")
      Numput(GuiHwnd,TInfo,8, "PTR")
      Numput(GuiHwnd,TInfo,8+A_PtrSize, "PTR")
      ;Numput(&text,TInfo,36)
      Detecthiddenwindows,on
      Sendmessage,1028,0,&TInfo,,ahk_id %TThwnd%
      SendMessage,1048,0,300,,ahk_id %TThwnd%
   }
   Varsetcapacity(TInfo,6*4+6*A_PtrSize,0)
   Numput(6*4+6*A_PtrSize,TInfo, "UInt")
   Numput(1|16,TInfo,4, "UInt")
   Numput(GuiHwnd,TInfo,8, "PTR")
   Numput(con,TInfo,8+A_PtrSize, "PTR")
   VarSetCapacity(ANSItext, StrPut(text, ""))
    StrPut(text, &ANSItext, "")
   Numput(&ANSIText,TInfo,6*4+3*A_PtrSize, "PTR")

   Detecthiddenwindows,on
   If (Modify)
      SendMessage,1036,0,&TInfo,,ahk_id %TThwnd%
   Else {
      Sendmessage,1028,0,&TInfo,,ahk_id %TThwnd%
      SendMessage,1048,0,300,,ahk_id %TThwnd%
   }
   DetectHiddenWindows %l_DetectHiddenWindows%
}
CreateTooltipControl(hwind)
{
   Ret:=DllCall("CreateWindowEx"
   ,"Uint",0
   ,"Str","TOOLTIPS_CLASS32"
   ,"PTR",0
   ,"Uint",2147483648 | 3
   ,"Uint",-2147483648
   ,"Uint",-2147483648
   ,"Uint",-2147483648
   ,"Uint",-2147483648
   ,"PTR",hwind
   ,"PTR",0
   ,"PTR",0
   ,"PTR",0, "PTR")
   Return Ret
}
Back to top
fragman



Joined: 13 Oct 2009
Posts: 1191

PostPosted: Sat May 28, 2011 4:15 pm    Post subject: Reply with quote

I know, I'm explicitly converting it to ANSI because the tooltips didn't work with the Unicode version of AHK_L. There might be Unicode versions of the messages used for the tooltip controls, but I don't know about them. Feel free to look them up on MSDN and post a working version Smile
Back to top
View user's profile Send private message
art



Joined: 23 Sep 2008
Posts: 39

PostPosted: Fri Jun 17, 2011 8:39 am    Post subject: Reply with quote

[ AHK, AHK_L compatible ]

Code:


;================================================================================
AddToolTip(CtrlHwnd,text,Modify=0) {   ; ***** Add Multiline ToolTips to any Gui Control *****                       [ AHK, AHK_L compatible ]
   Static TThwnd, GuiHwnd, Ptr   ; - 'Text' and 'Picture' Controls requires a g-label to be defined.
   If (!TThwnd){         ; - 'ComboBox' = Drop-Down button + Edit (Get hWnd of the 'Edit'   control using "ControlGet" command).
      Gui,+LastFound      ; - 'ListView' = ListView + Header       (Get hWnd of the 'Header' control using "ControlGet" command).
      GuiHwnd:=WinExist()
      TThwnd:=DllCall("CreateWindowEx","Uint",0,"Str","TOOLTIPS_CLASS32","Uint",0,"Uint",2147483648 | 3,"Uint",-2147483648
         ,"Uint",-2147483648,"Uint",-2147483648,"Uint",-2147483648,"Uint",GuiHwnd,"Uint",0,"Uint",0,"Uint",0)
      Ptr:=(A_PtrSize ? "Ptr" : "UInt"), DllCall("uxtheme\SetWindowTheme","Uint",TThwnd,Ptr,0,"UintP",0)   ; TTM_SETWINDOWTHEME
   }
   Varsetcapacity(TInfo,44,0), Numput(44,TInfo), Numput(1|16,TInfo,4), Numput(GuiHwnd,TInfo,8), Numput(CtrlHwnd,TInfo,12), Numput(&text,TInfo,36)
   !Modify   ? (DllCall("SendMessage",Ptr,TThwnd,"Uint",1028,Ptr,0,Ptr,&TInfo,Ptr))         ; TTM_ADDTOOL = 1028 (used to add a tool, and assign it to a control)
      . (DllCall("SendMessage",Ptr,TThwnd,"Uint",1048,Ptr,0,Ptr,A_ScreenWidth))      ; TTM_SETMAXTIPWIDTH = 1048 (This one allows the use of multiline tooltips)
   DllCall("SendMessage",Ptr,TThwnd,"UInt",(A_IsUnicode ? 0x439 : 0x40c),Ptr,0,Ptr,&TInfo,Ptr)   ; TTM_UPDATETIPTEXT (OLD_MSG=1036) (used to adjust the text of a tip)
}

Back to top
View user's profile Send private message
fragman



Joined: 13 Oct 2009
Posts: 1191

PostPosted: Fri Jun 17, 2011 9:47 am    Post subject: Reply with quote

I see you used A_IsUnicode in the Sendmessage call, so I suppose it supports Unicode now?

I noticed that tooltips won't show on DropDownLists/Comboboxes, any idea why?
Back to top
View user's profile Send private message
art



Joined: 23 Sep 2008
Posts: 39

PostPosted: Fri Jun 17, 2011 10:28 am    Post subject: Reply with quote

@fragman

The function i post at http://www.autohotkey.com/forum/viewtopic.php?t=30300&p=452514#452514 is working for all controls created using
- jballi's example posted at http://www.autohotkey.com/forum/viewtopic.php?t=30300&p=267487#267487 and
- uni guest's example posted at http://www.autohotkey.com/forum/viewtopic.php?t=30300&p=447939#447939.

Tested on Windows XP-SP3 and Windows 7 with both AHK 1.0.48.05 and AHK_L 1.0.92.02.
Back to top
View user's profile Send private message
Astrid
Guest





PostPosted: Mon Aug 29, 2011 5:00 pm    Post subject: Reply with quote

how would I extend the time the tooltip shows itself?

after sorting through several different approaches to create a basic tooltip method for just text labels in a gui this one seems simpler than most (thanks to art for the ahk_L validation) however it seems to be only 5 seconds and the tip closes itself

thanks a lot
Back to top
art



Joined: 23 Sep 2008
Posts: 39

PostPosted: Sun Sep 04, 2011 7:01 am    Post subject: Reply with quote

@Astrid
The notification's display time is a windows feature.
To change the time globally for windows follow this guide: Increase Windows 7 Notifiction Display Time
Back to top
View user's profile Send private message
Guest






PostPosted: Sun Sep 04, 2011 8:47 am    Post subject: Reply with quote

hi, i tested the thread first post and got this result, can somebody explain, why it only shows the first letter ?



i am using AHK_L latest version and Windows XP 32bit
Back to top
Guest






PostPosted: Sun Sep 04, 2011 9:01 am    Post subject: Reply with quote

please delete my last post, thanks
Back to top
tfwall112



Joined: 17 Sep 2011
Posts: 16

PostPosted: Sat Nov 12, 2011 10:04 pm    Post subject: A little help please Reply with quote

OK, I finally got this script to work for me, but when I hover for a tooltip, it only shows the first letter (much like the last post, and he didnt leave a fix lol)

Can someone tell me where I need to look?

Thanks, Terry
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page Previous  1, 2, 3  Next
Page 2 of 3

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group