Sign in to follow this  
Followers 0
nadigo

activate a GUI after a few second of hover over GUI

3 posts in this topic

Hi,

I am trying to crate an empty GUI so that when the mouse is hovered on top of it for more than 3 sec a new menu will slide from it.

do i need to use

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
can I use it with an empty GUI ? do I need a control ?

thanks,

Nadav

Share this post


Link to post
Share on other sites



There are geekier ways (register and handle messages), but a simple loop that checks if your GUI is active and uses MouseGetPos() to see if the mouse is over the GUI would be much easier:

#include <GuiConstantsEx.au3>

Global $hGUI, $idButton, $f_Visible, $iTimer

$hGUI = GUICreate("", 400, 300)
$idButton = GUICtrlCreateButton("Click Me!", 150, 135, 100, 30)
GUISetState()
_HideStuff()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $idButton
            MsgBox(64, "Button", "You clicked the button!", 3)
    EndSwitch

    If $f_Visible Then
        If Not _CheckMouseOver() Then _HideStuff()
    Else
        If _CheckMouseOver() Then
            If $iTimer Then
                If TimerDiff($iTimer) >= 3000 Then
                    _ShowStuff()
                EndIf
            Else
                $iTimer = TimerInit()
            EndIf
        EndIf
    EndIf
WEnd

Func _CheckMouseOver()
    Local $RET = False
    If WinActive($hGUI) Then
        Local $aMousePos = MouseGetPos()
        Local $aGuiPos = WinGetPos($hGUI)
        If ($aMousePos[0] > $aGuiPos[0]) And ($aMousePos[0] < ($aGuiPos[0] + $aGuiPos[2])) And _
                ($aMousePos[1] > $aGuiPos[1]) And ($aMousePos[1] < ($aGuiPos[1] + $aGuiPos[3])) Then
            $RET = True
        EndIf
    EndIf
    Return $RET
EndFunc   ;==>_CheckMouseOver

Func _ShowStuff()
    $f_Visible = True
    $iTimer = 0
    GUICtrlSetState($idButton, $GUI_SHOW)
    GUICtrlSetState($idButton, $GUI_ENABLE)
EndFunc   ;==>_ShowStuff

Func _HideStuff()
    $f_Visible = False
    $iTimer = 0
    GUICtrlSetState($idButton, $GUI_DISABLE)
    GUICtrlSetState($idButton, $GUI_HIDE)
EndFunc   ;==>_HideStuff

:graduated:


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

That was a very good GUI hover effect. I was surprised to see it done so simple.

Very good job

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  
Followers 0