Jump to content

Change label when mouse hovers certain button?


sensalim
 Share

Recommended Posts

Something like this in your while loop:

While 1
    $mouse = GUIGetCursorInfo ()
    Select
        Case $mouse[4] = $button1
            GUICtrlSetData ($label1, "Hovering on Button 1")
    EndSelect
WEnd
Link to comment
Share on other sites

Thanks all.

Bert, that loop makes flickers... lots of flickers on that label.

How do I reduce the flickers... sleep()?

Edit:

I added sleep(100) - no more flickers but response level is not acceptable.

I changed it to sleep(50) and things look great. Anything wrong with sleep(50) or 100?

Edited by sensalim
Link to comment
Share on other sites

Thanks all.

Bert, that loop makes flickers... lots of flickers on that label.

How do I reduce the flickers... sleep()?

Edit:

I added sleep(100) - no more flickers but response level is not acceptable.

I changed it to sleep(50) and things look great. Anything wrong with sleep(50) or 100?

Probably a more efficient way of dealing with it is recording what the mouse if over and then checking that when also. Then if the mouse is over the same control as it was last time it won't set the data... I'll post an example in a second

GuiCreate('Testing Beep', 400, 40)

$btnStart = GuiCtrlCreateButton('Start', 5, 5, 185, 30)

$btnStop = GuiCtrlCreateButton('Stop', 205, 5, 185, 30)

$lastHovered = -1

GuiSetState()

While 1
    $mouse = GUIGetCursorInfo ()
    Select
        Case $mouse[4] = $btnStart
            If $lastHovered <> $btnStart then 
                GUICtrlSetData ($btnStart, "Start HOVER")
            EndIf
            $lastHovered = $btnStart
        Case $mouse[4] = $btnStop 
            If $lastHovered <> $btnStop then 
                GUICtrlSetData ($btnStop, "Stop HOVER")
            EndIf       
            $lastHovered = $btnStop
        Case Else 
            If $lastHovered = $btnStart and GuiCtrlRead($btnStart) = 'Start HOVER' then 
                GUICtrlSetData ($btnStart, "Start")
                $lastHovered = -1
            ElseIf $lastHovered = $btnStop and GuiCtrlRead($btnStop) = 'Stop HOVER' then
                GUICtrlSetData ($btnStop, "Stop")
                $lastHovered = -1
            ENdIf
    EndSelect
    
    Switch GuiGetMsg() 
        Case -3 
            Exit 
            
    EndSwitch
WEnd
Edited by Piano_Man
My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]
Link to comment
Share on other sites

Hm I'm getting an error after assigning a function to button1, saying mouse is not an array...

Edit:

I realize that my script is using

Opt("GUIOnEventMode", 1)

and that does not work well... how do I do it with this option?

or another way to do this...

Thanks!

Edited by sensalim
Link to comment
Share on other sites

  • Moderators

Hm I'm getting an error after assigning a function to button1, saying mouse is not an array...

Edit:

I realize that my script is using

Opt("GUIOnEventMode", 1)

and that does not work well... how do I do it with this option?

or another way to do this...

Thanks!

A little effort on your part would be ... well... GREAT!!!

How about you make us an example GUI to work with so we don't have to waste any of our time serving your request?

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Did something similar with tooltips when mouse passed over button(s), would be easy to modify

http://www.autoitscript.com/forum/index.ph...st&p=234475

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

hi,

Event mode 1 example using minimal cpu and crisp response when hovering.

#include <GuiConstants.au3>

Opt("GUIOnEventMode", 1)

Global $But[6], $bX = 5, $Last

$Gui = GUICreate(":-)", 330, 55)
$Lbl = GUICtrlCreateLabel("", 5, 5, 320, 15, $SS_CENTER)
For $i = 1 To 5
    $But[$i] = GUICtrlCreateButton("Button " & $i, $bX, 25, 60, 20)
    $bX += 65
Next
GUISetOnEvent($GUI_EVENT_CLOSE, "Close", $Gui)
GUISetState(@SW_SHOW, $Gui)

While 1
    Sleep(10)
    Hover()
WEnd

Func Hover()
    $GGCI = GUIGetCursorInfo($Gui)
    If $GGCI[4] <> $Last Then
        GUICtrlSetData($Lbl, _Data($GGCI[4]))
        $Last = $GGCI[4]
    EndIf
EndFunc 

Func _Data($cID)
    For $i = 1 To 5
        If $cID = $But[$i] Then Return "Button " & $i
    Next
    Return ""
EndFunc

Func Close()
    Exit
EndFunc

Cheers

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...