Jump to content
Sign in to follow this  
lemony

Getting the text of the listbox item on mouseover?

Recommended Posts

Hey guys, please check out my code (posted below). I need to be able to somehow get the text of the listbox item on a mouseover. I can do it "on click", but I have no idea what to do for "on mouseover".

Please help if you can. Thanks!

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <GuiListBox.au3>

Opt("GUIOnEventMode", 1)
$Form1 = GUICreate("Form1", 418, 356, 410, 474)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
$List1 = GUICtrlCreateList("", 8, 8, 401, 214)
GUICtrlSetData($List1, "Item #01|Item #02|Item #03|Item #04|Item #05|Item #06|Item #07|Item #08|Item #09|Item #10")
GUICtrlSetOnEvent($List1, "List1Click")
$Label1 = GUICtrlCreateLabel("Shows selected listbox item:", 8, 232, 136, 17)
$Label2 = GUICtrlCreateLabel("Needs to show the listbox item that the mouse is currently hovered over:", 8, 296, 342, 17)
$Input1 = GUICtrlCreateInput("", 8, 256, 401, 21, BitOR($ES_AUTOHSCROLL,$ES_READONLY))
$Input2 = GUICtrlCreateInput("How can this be done?", 8, 320, 401, 21, BitOR($ES_AUTOHSCROLL,$ES_READONLY))
GUISetState(@SW_SHOW)

While 1
  Sleep(100)
WEnd

Func Form1Close()
  Exit
EndFunc

Func List1Click()
  GUICtrlSetData($Input1, _GUICtrlListBox_GetText($List1, _GUICtrlListBox_GetCurSel($List1)))
EndFunc
Edited by lemony

Share this post


Link to post
Share on other sites

This seems to work for me:

GUICreate("My GUI Window",900,500)
GUISetState()
While 1
AutoItSetOption("MouseCoordMode",0)
$x1 = ;left hand side of mouseover area (+ left border of GUI)
$x2 = ;right hand side of mouseover area (+ left border of GUI)
$y1 = ;top side of mouseover area (+ top border of GUI)
$y2 = ;bottom side of mouseover area (+ top border of GUI)
If MouseGetPos(0) > $x1 and MouseGetPos(0) < $x2 and MouseGetPos(1) > $y1 and MouseGetPos(1) < $y2 Then
    MsgBox(64,"Info","MouseOver!!")
EndIf
Wend

But it might make larger GUIs slower.

I hope this helps.

Share this post


Link to post
Share on other sites

Hey NumberDaemon, thanks for your reply.

I know what you are trying to show me but unfortunately that method does not help me.

In that script I posted, the same action that occurs when you click the listbox items needs to happen when hovering over (mousing over) the listbox items instead. I need an elegant solution if anyone knows one. Thanks!

Share this post


Link to post
Share on other sites

Add these to your example:

GUISetOnEvent($GUI_EVENT_MOUSEMOVE, "On_MOUSEMOVE")


Func On_MOUSEMOVE()
    Local $aCI = GUIGetCursorInfo(), $aCtrlPos, $x, $sText = ""
    If @error Or $aCI[4] <> $List1 Then Return GUICtrlSetData($Input2, $sText)
    $aCtrlPos = ControlGetPos(@GUI_WinHandle, "", $aCI[4])
    $x = _GUICtrlListBox_ItemFromPoint($aCI[4], $aCI[0]-$aCtrlPos[0], $aCI[1]-$aCtrlPos[1])
    If $x > -1 Then $sText = _GUICtrlListBox_GetText($aCI[4], $x)
    GUICtrlSetData($Input2, $sText)
EndFunc
Edited by Siao

"be smart, drink your wine"

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...