showing a ToolTip when Mouse cursor over on items of ListView Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
Tomer
Posts: 366
Joined: 21 Aug 2016, 05:11

showing a ToolTip when Mouse cursor over on items of ListView

07 Apr 2019, 03:51

Hello,

i have a script with:
1. Buttons (3)
2. ListView (1)

the script using a function that gives you a ToolTip (msg) when your Mouse cursor over only on the Buttons (each button returns its name).

However my question is if i can get the SAME for the items of the ListView ?
so i'll get for each item (LV_Add) a ToolTip with its name.

Thanks in advance!

Code: Select all

Gui, Add, Button,, Over your mouse here 1 - works! :)
Gui, Add, Button,, Over your mouse here 2 - works@ :)
Gui, Add, Button,, Over your mouse here 3 - works# :)
Gui Add, ListView,, test
LV_Add("" 1, "Over your mouse here 1 - doesnt works! :(")
LV_Add("" 2, "Over your mouse here 2@ - doesnt works! :(")
LV_Add("" 3, "Over your mouse here 3# - doesnt works! :(")
Gui, Show,,




hCurs:=DllCall("LoadCursor","UInt",NULL,"Int",32649,"UInt") ;IDC_HAND
OnMessage(0x200,"WM_MOUSEMOVE")
Return


WM_MOUSEMOVE(wParam, lParam, Msg)

   {
       ControlGetText, TXT_1, Button1
       ControlGetText, TXT_2, Button2
       ControlGetText, TXT_3, Button3
	

MouseGetPos,,,,ctrl
If ctrl in Button1
{
    ToolTip, %TXT_1%
}
else
If ctrl in Button2
{
    ToolTip, %TXT_2%
}
else
If ctrl in Button3
{
    ToolTip, %TXT_3%
}
else
{
	ToolTip
}
   }
Odlanir
Posts: 659
Joined: 20 Oct 2016, 08:20

Re: Help with showing a ToolTip when Mouse cursor over on item

07 Apr 2019, 04:38

I think you must select an Item to get the text:

Code: Select all

WM_MOUSEMOVE(wParam, lParam, Msg) {
    ControlGetText, TXT_1, Button1
    ControlGetText, TXT_2, Button2
    ControlGetText, TXT_3, Button3
    ControlGet, OutputVar, List, Focused, SysListView321
    MouseGetPos,,,,ctrl
    If SubStr(ctrl,1,6) = "Button" {
        b := SubStr(ctrl, 7,1)
        ToolTip, % TXT_%b%
    } else If (ctrl = "SysListView321") {
        ToolTip, % OutputVar
    } else {
        ToolTip
    }
}
____________________________________________________________________________
Windows 10 Pro 64 bit - Autohotkey v1.1.30.01 64-bit Unicode
User avatar
Tomer
Posts: 366
Joined: 21 Aug 2016, 05:11

Re: showing a ToolTip when Mouse cursor over on items of ListView

07 Apr 2019, 04:54

if "select" is a must so i add a "checked" to the listview,
but tooltip won't disappear when you unslect the item:

Code: Select all

Gui, Add, Button,, Over your mouse here 1 - works! :)
Gui, Add, Button,, Over your mouse here 2 - works@ :)
Gui, Add, Button,, Over your mouse here 3 - works# :)
Gui Add, ListView, Checked, test
LV_Add("" 1, "Over your mouse here 1 - doesnt works! :(")
LV_Add("" 2, "Over your mouse here 2@ - doesnt works! :(")
LV_Add("" 3, "Over your mouse here 3# - doesnt works! :(")
Gui, Show,,




hCurs:=DllCall("LoadCursor","UInt",NULL,"Int",32649,"UInt") ;IDC_HAND
OnMessage(0x200,"WM_MOUSEMOVE")
Return


WM_MOUSEMOVE(wParam, lParam, Msg) {
    ControlGetText, TXT_1, Button1
    ControlGetText, TXT_2, Button2
    ControlGetText, TXT_3, Button3
    ControlGet, OutputVar, List, Focused, SysListView321
    MouseGetPos,,,,ctrl
    If SubStr(ctrl,1,6) = "Button" {
        b := SubStr(ctrl, 7,1)
        ToolTip, % TXT_%b%
    } else If (ctrl = "SysListView321") {
        ToolTip, % OutputVar
    } else {
        ToolTip
    }
}
Kobaltauge
Posts: 264
Joined: 09 Mar 2019, 01:52
Location: Germany
Contact:

Re: Help with showing a ToolTip when Mouse cursor over on item

07 Apr 2019, 05:05

I'd changed your Tooltip to the "ctrl" variable. And as you can see, on the list elements it doesn't change. Unfortunately WindowsSpy.ahk doesn't register any change, too.
I'd tried a few things with ControlGet (https://www.autohotkey.com/docs/commands/ControlGet.htm#Hwnd) but nothing worked.

The video is to big for the board. See it on Imgur https://imgur.com/a/zxDvo9A
User avatar
Tomer
Posts: 366
Joined: 21 Aug 2016, 05:11

Re: showing a ToolTip when Mouse cursor over on items of ListView

07 Apr 2019, 05:51

Thanks for your help.
I see, in fact, thats my problem i cant control of each "LV_Add",
only for the entrie ListView..

if someone could resolve this somehow,
ill be thankful.

thanks
Kobaltauge
Posts: 264
Joined: 09 Mar 2019, 01:52
Location: Germany
Contact:

Re: showing a ToolTip when Mouse cursor over on items of ListView

08 Apr 2019, 00:18

Tomer wrote:
I'm just stumbled over this library by Pullover or Just Me. Probably it includes something to solve your problem.

https://www.autohotkey.com/boards/viewtopic.php?f=6&t=137
just me
Posts: 9423
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: showing a ToolTip when Mouse cursor over on items of ListView  Topic is solved

29 Apr 2019, 05:03

@Tomer: A simple approach

Code: Select all

#NoEnv
SetBatchLines,  -1

; GUI: added control variables
Gui, Add, Button, vBtn1, Over your mouse here 1 - works! :)
Gui, Add, Button, vBtn2, Over your mouse here 2 - works@ :)
Gui, Add, Button, vBtn3, Over your mouse here 3 - works# :)
Gui, Add, ListView, vLV1, Test
LV_Add("", "Over your mouse here 1 - doesnt works! :(")
LV_Add("", "Over your mouse here 2@ - doesnt works! :(")
LV_Add("", "Over your mouse here 3# - doesnt works! :(")
Gui, Show, , Test

OnMessage(0x0200, "WM_MOUSEMOVE")
Return

GuiClose:
ExitApp

WM_MOUSEMOVE(wParam, lParam, Msg, Hwnd) {
   ; LVM_HITTEST   -> docs.microsoft.com/en-us/windows/desktop/Controls/lvm-hittest
   ; LVHITTESTINFO -> docs.microsoft.com/en-us/windows/desktop/api/Commctrl/ns-commctrl-taglvhittestinfo
   TT := ""
   If A_GuiControl In Btn1,Btn2,Btn3
      GuiControlGet, TT, , %A_GuiControl%
   Else If (A_GuiControl = "LV1") {
      VarSetCapacity(LVHTI, 24, 0) ; LVHITTESTINFO
      , NumPut(lParam & 0xFFFF, LVHTI, 0, "Int")
      , NumPut((lParam >> 16) & 0xFFFF, LVHTI, 4, "Int")
      , Item := DllCall("SendMessage", "Ptr", Hwnd, "UInt", 0x1012, "Ptr", 0, "Ptr", &LVHTI, "Int") ; LVM_HITTEST
      If (Item >= 0) && (NumGet(LVHTI, 8, "UInt") & 0x0E) { ; LVHT_ONITEM
         Gui, ListView, %A_GuiControl%
         LV_GetText(TT, Item + 1)
      }
   }
   ToolTip, %TT%
}
User avatar
Tomer
Posts: 366
Joined: 21 Aug 2016, 05:11

Re: showing a ToolTip when Mouse cursor over on items of ListView

30 Apr 2019, 08:56

charm! :clap:

thank you just me !

p.s:
1. in the Listview,
how i can add extra different text in the tooltip for each lv_add instead just show the name of each lv_add ?

Edit:
think i solved this:

Code: Select all

#NoEnv
SetBatchLines,  -1

; GUI: added control variables

Gui, Add, ListView, vLV1, Test
LV_Add("", "tomer")
LV_Add("", "mike")
LV_Add("", "david")
Gui, Show, , Test

OnMessage(0x0200, "WM_MOUSEMOVE")
Return

GuiClose:
ExitApp

WM_MOUSEMOVE(wParam, lParam, Msg, Hwnd) {
   ; LVM_HITTEST   -> docs.microsoft.com/en-us/windows/desktop/Controls/lvm-hittest
   ; LVHITTESTINFO -> docs.microsoft.com/en-us/windows/desktop/api/Commctrl/ns-commctrl-taglvhittestinfo
   TT := ""
 If (A_GuiControl = "LV1") {
      VarSetCapacity(LVHTI, 24, 0) ; LVHITTESTINFO
      , NumPut(lParam & 0xFFFF, LVHTI, 0, "Int")
      , NumPut((lParam >> 16) & 0xFFFF, LVHTI, 4, "Int")
      , Item := DllCall("SendMessage", "Ptr", Hwnd, "UInt", 0x1012, "Ptr", 0, "Ptr", &LVHTI, "Int") ; LVM_HITTEST
      If (Item >= 0) && (NumGet(LVHTI, 8, "UInt") & 0x0E) { ; LVHT_ONITEM
         Gui, ListView, %A_GuiControl%
         LV_GetText(TT, Item + 1)
      }
   }
   if TT = tomer
	ToolTip, %TT% text1
   else
	if TT = mike
		ToolTip, %TT% text2
   else
	if TT = david
	     ToolTip, %TT% text3
	else
		 ToolTip
   
}
(maybe better method ?)

2. for what SetBatchLines, -1 needed for this kind of script ?
I didnt notice any difference
just me
Posts: 9423
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: showing a ToolTip when Mouse cursor over on items of ListView

30 Apr 2019, 09:54

Hi Tomer,

1. If all ListView items are unique, I'd prefer an associative array:

Code: Select all

#NoEnv
SetBatchLines,  -1

ItemTips := []
; GUI: added control variables
Gui, Add, Button, vBtn1, Over your mouse here 1 - works! :)
Gui, Add, Button, vBtn2, Over your mouse here 2 - works@ :)
Gui, Add, Button, vBtn3, Over your mouse here 3 - works# :)
Gui, Add, ListView, vLV1, Test
LV_Add("", "tomer")
ItemTips["tomer"] := "Tomer's ToolTip"
LV_Add("", "mike")
ItemTips["mike"] := "Mike's ToolTip"
LV_Add("", "david")
ItemTips["david"] := "David's ToolTip"
Gui, Show, , Test

OnMessage(0x0200, "WM_MOUSEMOVE")
Return

GuiClose:
ExitApp

WM_MOUSEMOVE(wParam, lParam, Msg, Hwnd) {
   ; LVM_HITTEST   -> docs.microsoft.com/en-us/windows/desktop/Controls/lvm-hittest
   ; LVHITTESTINFO -> docs.microsoft.com/en-us/windows/desktop/api/Commctrl/ns-commctrl-taglvhittestinfo
   Global ItemTips
   TT := ""
   If A_GuiControl In Btn1,Btn2,Btn3
      GuiControlGet, TT, , %A_GuiControl%
   Else If (A_GuiControl = "LV1") {
      VarSetCapacity(LVHTI, 24, 0) ; LVHITTESTINFO
      , NumPut(lParam & 0xFFFF, LVHTI, 0, "Int")
      , NumPut((lParam >> 16) & 0xFFFF, LVHTI, 4, "Int")
      , Item := DllCall("SendMessage", "Ptr", Hwnd, "UInt", 0x1012, "Ptr", 0, "Ptr", &LVHTI, "Int") ; LVM_HITTEST
      If (Item >= 0) && (NumGet(LVHTI, 8, "UInt") & 0x0E) { ; LVHT_ONITEM
         Gui, ListView, %A_GuiControl%
         LV_GetText(ItemText, Item + 1)
         TT := ItemTips[ItemText]
      }
   }
   ToolTip, %TT%
}
2. WM_MOUSEMOVE notifications may be posted at frequent intervals. That's why the script should process them as fast as possible to reduce the chance to miss some of them.
Osprey
Posts: 453
Joined: 18 Nov 2017, 05:50

Re: showing a ToolTip when Mouse cursor over on items of ListView

30 Apr 2019, 21:58

Tomer wrote:
30 Apr 2019, 08:56
how i can add extra different text in the tooltip for each lv_add instead just show the name of each lv_add ?
This is how I did it:

Code: Select all

#NoEnv
SetBatchLines,  -1

blah1 = This is blah1
blah2 = This is blah2
blah3 = This is blah3

Gui, Add, ListView, vLV1, Test
LV_Add("", "blah1")
LV_Add("", "blah2")
LV_Add("", "blah3")
Gui, Show, , Test

OnMessage(0x0200, "WM_MOUSEMOVE")
Return

GuiClose:
ExitApp

WM_MOUSEMOVE(wParam, lParam, Msg, Hwnd) {
   global
   ; LVM_HITTEST   -> docs.microsoft.com/en-us/windows/desktop/Controls/lvm-hittest
   ; LVHITTESTINFO -> docs.microsoft.com/en-us/windows/desktop/api/Commctrl/ns-commctrl-taglvhittestinfo
   TT := ""
   If A_GuiControl In Btn1,Btn2,Btn3
      GuiControlGet, TT, , %A_GuiControl%
   Else If (A_GuiControl = "LV1") {
      VarSetCapacity(LVHTI, 24, 0) ; LVHITTESTINFO
      , NumPut(lParam & 0xFFFF, LVHTI, 0, "Int")
      , NumPut((lParam >> 16) & 0xFFFF, LVHTI, 4, "Int")
      , Item := DllCall("SendMessage", "Ptr", Hwnd, "UInt", 0x1012, "Ptr", 0, "Ptr", &LVHTI, "Int") ; LVM_HITTEST
      If (Item >= 0) && (NumGet(LVHTI, 8, "UInt") & 0x0E) { ; LVHT_ONITEM
         Gui, ListView, %A_GuiControl%
         LV_GetText(TT, Item + 1)
         TT := %TT%
      }
   }
   ToolTip, %TT%
}
User avatar
Tomer
Posts: 366
Joined: 21 Aug 2016, 05:11

Re: showing a ToolTip when Mouse cursor over on items of ListView

01 May 2019, 02:33

thanks @just me and @Osprey i like both methods!

may last wish please:
i want to show the tooltip with mouse right click instead overing the mouse.
i guess its something to do with OnMessage(0x0200, "WM_MOUSEMOVE") but i faild to make it work proprly.

thanks in advance
just me
Posts: 9423
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: showing a ToolTip when Mouse cursor over on items of ListView

01 May 2019, 02:51

That's a task for GuiContextMenu::

Code: Select all

#NoEnv
SetBatchLines,  -1

ItemTips := []
; GUI: added control variables
Gui, Add, Button, vBtn1, Over your mouse here 1 - works! :)
Gui, Add, Button, vBtn2, Over your mouse here 2 - works@ :)
Gui, Add, Button, vBtn3, Over your mouse here 3 - works# :)
Gui, Add, ListView, vLV1, Test
LV_Add("", "tomer")
ItemTips["tomer"] := "Tomer's ToolTip"
LV_Add("", "mike")
ItemTips["mike"] := "Mike's ToolTip"
LV_Add("", "david")
ItemTips["david"] := "David's ToolTip"
Gui, Show, , Test

Return

GuiClose:
ExitApp

GuiContextMenu:
   If (A_GuiEvent = "RightClick")
   {
      TT := ""
      If A_GuiControl In Btn1,Btn2,Btn3
         GuiControlGet, TT, , %A_GuiControl%
      Else If (A_GuiControl = "LV1") && (A_EventInfo)
      {
         Gui, ListView, %A_GuiControl%
         If (A_EventInfo = LV_GetNext())
         {
            LV_GetText(ItemText, A_EventInfo)
            TT := ItemTips[ItemText]
         }
      }
      ToolTip, %TT%
      If !(TT = "")
         SetTimer, RemoveToolTip, -1000
   }
Return

RemoveToolTip:
   ToolTip
Return
User avatar
Tomer
Posts: 366
Joined: 21 Aug 2016, 05:11

Re: showing a ToolTip when Mouse cursor over on items of ListView

01 May 2019, 03:34

Bravo

i changed the unshow tooltip to mouse left click instead settimer
but im not sure if i've done it in the best way... :wtf: :


EDIT2:

I think now its good!
thank you !

Code: Select all

#NoEnv
SetBatchLines,  -1



ItemTips := []
; GUI: added control variables
Gui, Add, Button, vBtn1, Over your mouse here 1 - works! :)
Gui, Add, Button, vBtn2, Over your mouse here 2 - works@ :)
Gui, Add, Button, vBtn3, Over your mouse here 3 - works# :)
Gui, Add, ListView, vLV1, Test
LV_Add("", "tomer")
ItemTips["tomer"] := "Tomer"
LV_Add("", "mike")
ItemTips["mike"] := "Mike's ToolTip"
LV_Add("", "david")
ItemTips["david"] := "David's ToolTip"
Gui, Show, , Test

Return

GuiClose:
ExitApp

GuiContextMenu:
   If (A_GuiEvent = "RightClick")
   {
      TT := ""
      If A_GuiControl In Btn1,Btn2,Btn3
         GuiControlGet, TT, , %A_GuiControl%
      Else If (A_GuiControl = "LV1") && (A_EventInfo)
      {
         Gui, ListView, %A_GuiControl%
         If (A_EventInfo = LV_GetNext())
         {
            LV_GetText(ItemText, A_EventInfo)
            TT := ItemTips[ItemText]
         }
      }
      ToolTip, %TT%
      GuiControl, Disable, LV1
      If !(TT = "")
         ~LButton::
{
	If GetKeyState("LButton", "P")
      IfWinActive, Test ; only when script is active
         if TT = ; only when tooltip is shown
	         Exit
             else
            {
               ToolTip
               sleep, 1 ; prevent select other item when tooltip show
               GuiControl, Enable, LV1
            }
}
return
   }
Return



just me
Posts: 9423
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: showing a ToolTip when Mouse cursor over on items of ListView

01 May 2019, 05:40

EDIT2:

I think now its good!
thank you !
Another example of code I always think "that cannot work" at first glance, but it actually does. If you really want to use the left mouse button, I suggest the following:

Code: Select all

#NoEnv
SetBatchLines,  -1

ItemTips := []
; GUI: added control variables
Gui, Add, Button, vBtn1, Over your mouse here 1 - works! :)
Gui, Add, Button, vBtn2, Over your mouse here 2 - works@ :)
Gui, Add, Button, vBtn3, Over your mouse here 3 - works# :)
Gui, Add, ListView, vLV1, Test
LV_Add("", "tomer")
ItemTips["tomer"] := "Tomer's ToolTip"
LV_Add("", "mike")
ItemTips["mike"] := "Mike's ToolTip"
LV_Add("", "david")
ItemTips["david"] := "David's ToolTip"
Gui, Show, , Test

Return

GuiClose:
ExitApp

GuiContextMenu:
   If (A_GuiEvent = "RightClick") {
      OnMessage(0x0201, "")
      TT := ""
      If A_GuiControl In Btn1,Btn2,Btn3
         GuiControlGet, TT, , %A_GuiControl%
      Else If (A_GuiControl = "LV1") && (A_EventInfo) {
         Gui, ListView, %A_GuiControl%
         If (A_EventInfo = LV_GetNext()) {
            LV_GetText(ItemText, A_EventInfo)
            TT := ItemTips[ItemText]
         }
      }
      ToolTip, %TT%
      If (TT <> "")
         OnMessage(0x0201, "WM_LBUTTONDOWN")
   }
Return

WM_LBUTTONDOWN() {
   Global TT
   If (TT <> "") {
      TT := ""
      ToolTip
   }
   OnMessage(0x0201, "")
   ; If the ListView was clicked, prevent message processing which might cause the selection of a new item.
   If (A_GuiControl = "LV1")
      Return 0
}
User avatar
Tomer
Posts: 366
Joined: 21 Aug 2016, 05:11

Re: showing a ToolTip when Mouse cursor over on items of ListView

05 May 2019, 02:14

Even though my method works, I will use yours.
Thanks alot once again @just me
hasantr
Posts: 933
Joined: 05 Apr 2016, 14:18
Location: İstanbul

Re: showing a ToolTip when Mouse cursor over on items of ListView

24 Jun 2020, 15:38

just me wrote:
29 Apr 2019, 05:03
@Tomer: A simple approach

Code: Select all

#NoEnv
SetBatchLines,  -1

; GUI: added control variables
Gui, Add, Button, vBtn1, Over your mouse here 1 - works! :)
Gui, Add, Button, vBtn2, Over your mouse here 2 - works@ :)
Gui, Add, Button, vBtn3, Over your mouse here 3 - works# :)
Gui, Add, ListView, vLV1, Test
LV_Add("", "Over your mouse here 1 - doesnt works! :(")
LV_Add("", "Over your mouse here 2@ - doesnt works! :(")
LV_Add("", "Over your mouse here 3# - doesnt works! :(")
Gui, Show, , Test

OnMessage(0x0200, "WM_MOUSEMOVE")
Return

GuiClose:
ExitApp

WM_MOUSEMOVE(wParam, lParam, Msg, Hwnd) {
   ; LVM_HITTEST   -> docs.microsoft.com/en-us/windows/desktop/Controls/lvm-hittest
   ; LVHITTESTINFO -> docs.microsoft.com/en-us/windows/desktop/api/Commctrl/ns-commctrl-taglvhittestinfo
   TT := ""
   If A_GuiControl In Btn1,Btn2,Btn3
      GuiControlGet, TT, , %A_GuiControl%
   Else If (A_GuiControl = "LV1") {
      VarSetCapacity(LVHTI, 24, 0) ; LVHITTESTINFO
      , NumPut(lParam & 0xFFFF, LVHTI, 0, "Int")
      , NumPut((lParam >> 16) & 0xFFFF, LVHTI, 4, "Int")
      , Item := DllCall("SendMessage", "Ptr", Hwnd, "UInt", 0x1012, "Ptr", 0, "Ptr", &LVHTI, "Int") ; LVM_HITTEST
      If (Item >= 0) && (NumGet(LVHTI, 8, "UInt") & 0x0E) { ; LVHT_ONITEM
         Gui, ListView, %A_GuiControl%
         LV_GetText(TT, Item + 1)
      }
   }
   ToolTip, %TT%
}
Since I do not have a very different demand, I would like to ask here without opening a new topic.
Can we get row and column numbers instead of content?

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: hugojans and 101 guests