 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
adamrgolf
Joined: 28 Dec 2006 Posts: 440
|
Posted: Thu Jul 03, 2008 8:10 am Post subject: Listview tooltip on mouse hover? |
|
|
is showing of row data in a listview possible by just hovering?
I'm trying to get something to do the following, accept without clicking:
| Code: | #SingleInstance,Force
OnExit,GuiClose
Gui,Add,Listview,vLV gLV AltSubmit,Name|Size
Gui,Show
Loop, %A_WinDir%\*.*
LV_Add("",A_LoopFileName,A_LoopFileSizeKB)
Return
LV:
If A_GuiEvent in Normal
{
LV_GetText(name,A_EventInfo,1)
LV_GetText(size,A_EventInfo,2)
tooltip, Name: %name%%A_Tab%Size: %size%
}
Return
GuiClose:
ExitApp |
Thanks!
Adam |
|
| Back to top |
|
 |
adamrgolf
Joined: 28 Dec 2006 Posts: 440
|
Posted: Wed Jul 09, 2008 9:07 pm Post subject: |
|
|
Anyone have any ideas?  |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 8688
|
Posted: Thu Jul 10, 2008 5:18 am Post subject: Re: Listview tooltip on mouse hover? |
|
|
| adamrgolf wrote: | | accept without clicking: |
It not possible, ( I guess ) to get a row text without selecting it first... but a row under mouse can be selected ( without clicking ) if you enable hot-track selection ( LVS_EX_TRACKSELECT LV0x8 ) style for the ListView Control.
This is what I mean:
| Code: | #SingleInstance,Force
OnExit,GuiClose
Gui,Add,Listview,vLV r10 gLV LV0x8 AltSubmit,Name|Size
LV_ModifyCol(1,150 )
Gui,Show
Loop, %A_WinDir%\*.*
LV_Add("",A_LoopFileName,A_LoopFileSizeKB)
Return
LV:
If ( A_GuiEvent="I" )
{
LV_GetText(name,A_EventInfo,1)
LV_GetText(size,A_EventInfo,2)
tooltip, Name: %name%%A_Tab%Size: %size%
SetTimer, ToolTipOff, -2000
}
Return
GuiClose:
ExitApp
ToolTipOff:
Tooltip
Return |
 _________________ URLGet - Internet Explorer based Downloader |
|
| Back to top |
|
 |
Micahs
Joined: 01 Dec 2006 Posts: 460
|
Posted: Fri Jul 11, 2008 8:46 am Post subject: |
|
|
Try this. It calcs the row from the mouse pos and displays the text from the first two columns. No Hot-Tracking!
I tweaked parts of my "Listview In-Cell Editing" script.
| Code: | #SingleInstance,Force
OnExit,GuiClose
Gui,Add,Listview, gLV vLV hwndLV_LView AltSubmit,Name|Size
Gui,Show
Loop, %A_WinDir%\*.*
LV_Add("",A_LoopFileName,A_LoopFileSizeKB)
tipDuration = 4000
ControlGetPos, LV_lx, LV_ly, LV_lw, LV_lh, , ahk_id %LV_LView% ;get info on listview
SysGet, SM_CXVSCROLL, 2 ;get width of vertical scrollbar
LVIR_LABEL = 0x0002 ;LVM_GETSUBITEMRECT constant - get label info
LVM_GETITEMCOUNT = 4100 ;gets total number of rows
LVM_SCROLL = 4116 ;scrolls the listview
LVM_GETTOPINDEX = 4135 ;gets the first displayed row
LVM_GETCOUNTPERPAGE = 4136 ;gets number of displayed rows
LVM_GETSUBITEMRECT = 4152 ;gets cell width,height,x,y
OnMessage(0x200, "WM_MOUSEMOVE")
Return
WM_MOUSEMOVE(wParam, lParam, msg, hwnd)
{
global
If(hwnd = LV_LView) ;only if the mouse moved over the listview
{ SendMessage, LVM_GETITEMCOUNT, 0, 0, , ahk_id %LV_LView%
LV_TotalNumOfRows := ErrorLevel ;get total number of rows
SendMessage, LVM_GETCOUNTPERPAGE, 0, 0, , ahk_id %LV_LView%
LV_NumOfRows := ErrorLevel ;get number of displayed rows
SendMessage, LVM_GETTOPINDEX, 0, 0, , ahk_id %LV_LView%
LV_topIndex := ErrorLevel ;get first displayed row
LV_mx := lParam & 0xFFFF ;get mouse x,y
LV_my := lParam >> 16
VarSetCapacity(LV_XYstruct, 16, 0) ;create struct
Loop,% LV_NumOfRows + 1 ;gets the current row and cell Y,H
{ LV_which := LV_topIndex + A_Index - 1 ;loop through each displayed row
NumPut(LVIR_LABEL, LV_XYstruct, 0) ;get label info constant
NumPut(A_Index - 1, LV_XYstruct, 4) ;subitem index
SendMessage, LVM_GETSUBITEMRECT, %LV_which%, &LV_XYstruct, , ahk_id %LV_LView% ;get cell coords
LV_RowY := NumGet(LV_XYstruct,4) ;row upperleft y
LV_RowY2 := NumGet(LV_XYstruct,12) ;row bottomright y2
LV_currColHeight := LV_RowY2 - LV_RowY ;get cell height
If(LV_my <= LV_RowY + LV_currColHeight) ;if mouse Y pos less than row pos + height
{ If(oldLV_which != LV_which)
{ LV_currRow := LV_which + 1 ;1-based current row
LV_currRow0 := LV_which ;0-based current row, if needed
LV_GetText(txt1, LV_currRow, 1)
LV_GetText(txt2, LV_currRow, 2)
ToolTip,Name: %txt1%%A_Tab%Size: %txt2%,,,19
SetTimer, killTip, %tipDuration%
}
oldLV_which := LV_which
Break
killTip:
tooltip,,,, 19
SetTimer, killTip, Off
Return
}
}
}
Else
{ oldLV_which=
tooltip,,,, 19
}
}
LV:
;~ If A_GuiEvent in Normal
;~ {
;~ LV_GetText(name,A_EventInfo,1)
;~ LV_GetText(size,A_EventInfo,2)
;~ tooltip, Name: %name%%A_Tab%Size: %size%
;~ }
Return
GuiClose:
ExitApp |
_________________
 |
|
| Back to top |
|
 |
adamrgolf
Joined: 28 Dec 2006 Posts: 440
|
Posted: Fri Jul 11, 2008 8:49 am Post subject: |
|
|
Holy crap Micahs, that is great!
Edit: This is perfect, exactly what I needed. Great work! |
|
| Back to top |
|
 |
Micahs
Joined: 01 Dec 2006 Posts: 460
|
Posted: Fri Jul 11, 2008 8:55 am Post subject: |
|
|
Glad you like it! Hope it helps. _________________
 |
|
| Back to top |
|
 |
ribbs2521
Joined: 28 Sep 2007 Posts: 273 Location: New York
|
Posted: Wed Sep 16, 2009 2:54 pm Post subject: |
|
|
I have been using Micahs' code for quite some time now and it is a great tool. The only thing I would like to change is the ability to have a delay.
I'm not sure how to implement this but an example would be like in a lot of forums, the tooltip is not immediate, there is a three or four second delay.
What I did was I just added a mouse coordinate check after two seconds and if the mouse hadn't moved, it would display the tip but it doesn't always work. I still get some tips that come up from rows I didn't hover over for a full two seconds. I believe it's because, by sleeping for two seconds and then checking again I'm causing a large queue of WM_MOUSEMOVE calls if it moves during those two seconds. If that made any sense.
So, I guess it may be as simple as telling it to kill the other WM_MOUSEMOVE threads each time a new one is started if that's possible.
Well, let me know what you think. |
|
| Back to top |
|
 |
Micahs
Joined: 01 Dec 2006 Posts: 460
|
Posted: Thu Sep 17, 2009 9:28 am Post subject: |
|
|
Here is an updated version and example: | Code: | #SingleInstance,Force
OnExit,GuiClose
Gui,Add,Listview, vLV hwndLV_LView AltSubmit,Name|Size
Gui,Show
Loop, %A_WinDir%\*.* ;just fill listview
LV_Add("",A_LoopFileName,A_LoopFileSizeKB)
OnMessage(0x200, "WM_MOUSEMOVE")
Return
WM_MOUSEMOVE(wParam, lParam, msg, hwnd)
{
global
If(hwnd = LV_LView) ;only if the mouse moved over the listview
{ LV_MouseGetCellPos(LV_CurrRow, LV_CurrCol, LV_LView)
If(oldLV_CurrRow != LV_CurrRow) ;if it has changed
{ oldLV_CurrRow := LV_CurrRow
ToolTip,,,, 20
counter := A_TickCount + 500
Loop ;loop for 500 ms and cancel tip if row changed
{ LV_MouseGetCellPos(LV_CurrRow, LV_CurrCol, LV_LView)
IfNotEqual, oldLV_CurrRow, %LV_CurrRow%
{ SetTimer, KillNow, -1
Return
}
looper := A_TickCount
IfGreater, looper, %counter%, Break
sleep, 150
}
LV_GetText(txt1, LV_currRow, 1)
LV_GetText(txt2, LV_currRow, 2)
SetTimer, killTip, 500
ToolTip,Name: %txt1%%A_Tab%Size: %txt2%,,,20
}
Return
killTip:
killTipCounter++
MouseGetPos, , , outWm, outK, 2
If(outK != LV_LView) or (killTipCounter >= 8) ;500ms*8 = ~4 secs
{ ;this lets us kill the tooltip immediately
KillNow:
SetTimer, killTip, Off
ToolTip,,,, 20
killTipCounter=0
Return
}
Return
}
Else ;if not over lv, destroy tip
{ SetTimer, killTip, -1 ;go now once
}
}
GuiClose:
ExitApp
Return
LV_MouseGetCellPos(ByRef LV_CurrRow, ByRef LV_CurrCol, LV_LView)
{
LVIR_LABEL = 0x0002 ;LVM_GETSUBITEMRECT constant - get label info
LVM_GETITEMCOUNT = 4100 ;gets total number of rows
LVM_SCROLL = 4116 ;scrolls the listview
LVM_GETTOPINDEX = 4135 ;gets the first displayed row
LVM_GETCOUNTPERPAGE = 4136 ;gets number of displayed rows
LVM_GETSUBITEMRECT = 4152 ;gets cell width,height,x,y
ControlGetPos, LV_lx, LV_ly, LV_lw, LV_lh, , ahk_id %LV_LView% ;get info on listview
SendMessage, LVM_GETITEMCOUNT, 0, 0, , ahk_id %LV_LView%
LV_TotalNumOfRows := ErrorLevel ;get total number of rows
SendMessage, LVM_GETCOUNTPERPAGE, 0, 0, , ahk_id %LV_LView%
LV_NumOfRows := ErrorLevel ;get number of displayed rows
SendMessage, LVM_GETTOPINDEX, 0, 0, , ahk_id %LV_LView%
LV_topIndex := ErrorLevel ;get first displayed row
CoordMode, MOUSE, RELATIVE
MouseGetPos, LV_mx, LV_my
LV_mx -= LV_lx, LV_my -= LV_ly
VarSetCapacity(LV_XYstruct, 16, 0) ;create struct
Loop,% LV_NumOfRows + 1 ;gets the current row and cell Y,H
{ LV_which := LV_topIndex + A_Index - 1 ;loop through each displayed row
NumPut(LVIR_LABEL, LV_XYstruct, 0) ;get label info constant
NumPut(A_Index - 1, LV_XYstruct, 4) ;subitem index
SendMessage, LVM_GETSUBITEMRECT, %LV_which%, &LV_XYstruct, , ahk_id %LV_LView% ;get cell coords
LV_RowY := NumGet(LV_XYstruct,4) ;row upperleft y
LV_RowY2 := NumGet(LV_XYstruct,12) ;row bottomright y2
LV_currColHeight := LV_RowY2 - LV_RowY ;get cell height
If(LV_my <= LV_RowY + LV_currColHeight) ;if mouse Y pos less than row pos + height
{ LV_currRow := LV_which + 1 ;1-based current row
LV_currRow0 := LV_which ;0-based current row, if needed
;LV_currCol is not needed here, so I didn't do it! It will always be 0. See my ListviewInCellEditing function for details on finding LV_currCol if needed.
LV_currCol=0
Break
}
}
}
| It now uses parts of my tooltipV2 function. This one originally used version one of the tooltip stuff. I had improved it but hadn't updated this accordingly. This more closely mimics normal tooltip behavior. There is a 500ms lag before the tip appears. It will stay for about 4 seconds. I also broke the LV row detection out into a function called "LV_MouseGetCellPos". Hope this helps.
Micahs _________________
 |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|