Code: Select all
#NoEnv
#Warn
SendMode Input
SetWorkingDir %A_ScriptDir%
#SingleInstance force
delimiter := "`n"
list=
(join%delimiter%
Lorem ipsum dolor sit amet, consetetur
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut l
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor
)
Gui, +Delimiter%delimiter%
Gui, Font, s12 w500, Verdana
Gui, Add, ListBox, r2 w300 +HScroll +VScroll, % list
Gui, Add, ListBox, r2 w300 +HScroll +VScroll, % list
Gui, Show
SetTimer, label, 200
return
label() {
static isTracking := 0x0
static lastX := ""
static lastY := ""
static lastFound := 0x0
static cb := Func("cb")
static fn0
static fn1
MouseGetPos, x, y,, hControl, 2
WinGetClass, controlClass, % "ahk_id " . hControl
if (controlClass = "ListBox") {
if (!isTracking || (hControl <> lastFound)) {
isTracking := true, lastFound := hControl
fn0 := cb.bind(hControl, false), fn1 := cb.bind(hControl, true)
}
if (x <> lastX || y <> lastY) {
lastX := x, lastY := y
SetTimer % fn0, -1
SetTimer % fn1, -500
SetTimer % fn0, -2500
}
} else {
ToolTip
isTracking := 0x0
}
}
cb(hControl, show) {
MouseGetPos, x, y,, hwnd, 2
if (hwnd <> hControl) {
ToolTip
return
}
itemPos := LBEX_ItemFromCursor(hControl)
if (itemPos > -1) {
WinGetPos, x,,,, % "ahk_id " . hControl
CoordMode, ToolTip, Screen
ToolTip % (show) ? LBEX_GetText(hControl, ++itemPos) : "", % x
} else ToolTip
}
LBEX_ItemFromCursor(hListBox) { ; from LBEX_ItemFromCursor by 'just me' - https://www.autohotkey.com/boards/viewtopic.php?p=66813#profile66885
static LB_ITEMFROMPOINT := 0x01A9
local
VarSetCapacity(_POINT_, 8, 0) ; POINT structure -> msdn.microsoft.com/en-us/library/dd162805(v=vs.85).aspx
DllCall("GetCursorPos", "Ptr", &_POINT_) ; -> msdn.microsoft.com/en-us/library/ms648390(v=vs.85).aspx
DllCall("ScreenToClient", "Ptr", hListBox, "Ptr", &_POINT_) ; -> msdn.microsoft.com/en-us/library/dd162952(v=vs.85).aspx
x := NumGet(_POINT_, 0, "UShort") ; only 16 bits are used by LB_ITEMFROMPOINT
y := NumGet(_POINT_, 4, "UShort") << 16 ; only 16 bits are used by LB_ITEMFROMPOINT
SendMessage % LB_ITEMFROMPOINT, 0, % (x + y),, % "ahk_id " . hListBox ; LB_ITEMFROMPOINT -> msdn.microsoft.com/en-us/library/bb761323(v=vs.85).aspx
if (ErrorLevel & 0xFFFF0000) ; the HIWORD of the return value is one if the cursor is outside the client area.
return -1
return (ErrorLevel & 0xFFFF) ; the return value contains the 0-based index of the item in the LOWORD.
}
LBEX_GetText(HLB, Index) { ; by 'just me' (https://github.com/AHK-just-me/LBEX/blob/master/Sources/LBEX.ahk)
Static LB_GETTEXT := 0x0189
Len := LBEX_GetTextLen(HLB, Index)
If (Len = -1)
Return ""
VarSetCapacity(Text, Len << !!A_IsUnicode, 0)
SendMessage, % LB_GETTEXT, % (Index - 1), % &Text, , % "ahk_id " . HLB
Return StrGet(&Text, Len)
}
LBEX_GetTextLen(HLB, Index) { ; by 'just me' (https://github.com/AHK-just-me/LBEX/blob/master/Sources/LBEX.ahk)
Static LB_GETTEXTLEN := 0x018A
SendMessage, % LB_GETTEXTLEN, % (Index - 1), 0, , % "ahk_id " . HLB
Return ErrorLevel
}
GuiClose:
ExitApp