Jump to content

OnHover UDF help?


Rawox
 Share

Recommended Posts

Hey!

I'm making a script, doh!

But the GUICtrlSetOnHover_UDF.au3 doesn't really make sense or something like that.

YES, I included the files

YES, I tried it:

$CloseLab = GUICtrlCreateLabel ( "Sluiten", 220, 310, 55, 20, $SS_CENTER )
_GUICtrl_SetOnHover ( $CloseLab, "_Hover_Func", "_Hover_Func" )

Func _Hover_Func ( $iCtrlID, $iParam )
    Local $iLabel_Color = 0xf9d2dd
    Local $iLabel_FontAttrib = 4
    
    If $iParam = 2 Then
        $iLabel_Color = 0xcf003a
        $iLabel_FontAttrib = 0
    EndIf
    
    Switch $iCtrlID
        Case $Label
            GUICtrlSetColor ( $iCtrlID, $iLabel_Color )
            GUICtrlSetFont ( $iCtrlID, Default, Default, $iLabel_FontAttrib )
    EndSwitch
EndFunc

NO, it does not work! But why? :D

Anyone??

Link to comment
Share on other sites

I will try to help.What I have below works.But I too had trouble with this UDF in the past.My problem turned out to be 2 different things.I am running Vista x64. So when using this UDF my scripts either had to be compiled first or I had to right-click the script file and run it as x86.Don't know if that applies to you.But like I said the script below worked for me as in the label changed colors on hover.Hope this helps. :D

The only thing I seen in your code was

Case $Label

should have been

Case $CloseLab

#include <GUICtrlSetOnHover_UDF.au3>
#include <StaticConstants.au3>
#include <GUIConstantsEx.au3>

GUICreate("My GUI")
$CloseLab = GUICtrlCreateLabel("Sluiten", 220, 310, 55, 20, $SS_CENTER)
_GUICtrl_SetOnHover($CloseLab, "_Hover_Func", "_Hover_Func")
GUISetState(@SW_SHOW)
While 1
    $msg = GUIGetMsg()

    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd
GUIDelete()
Func _Hover_Func($iCtrlID, $iParam)
    Local $iLabel_Color = 0xf9d2dd
    Local $iLabel_FontAttrib = 4

    If $iParam = 2 Then
        $iLabel_Color = 0xcf003a
        $iLabel_FontAttrib = 0
    EndIf

    Switch $iCtrlID
        Case $CloseLab
            GUICtrlSetColor($iCtrlID, $iLabel_Color)
            GUICtrlSetFont($iCtrlID, Default, Default, $iLabel_FontAttrib)
    EndSwitch
EndFunc  ;==>_Hover_Func
Link to comment
Share on other sites

Here is a similar example without any include files which works.

I hope it helps you understand how the GUICtrlSetOnHover_UDF.au3 works.

;
 Local $iLabel_FontAttrib, $iLabel_Color, $id, $CLFlg = False
 
 GUICreate("My GUI")
 $CloseLab = GUICtrlCreateLabel("Sluiten", 220, 310, 55, 20, 1);$SS_CENTER = 1, StaticConstants.au3
 GUICtrlSetFont($CloseLab, Default, 800, 4)
 GUISetState(@SW_SHOW)
 
 While 1
    $msg = GUIGetMsg()
    $id = _ControlGetHovered()
 
    Select
        Case $msg = -3;$GUI_EVENT_CLOSE = -3, GUIConstantsEx.au3
            ExitLoop
        Case $id = $CloseLab And Not $CLFlg; Hover label & not hovered before condition
            GUICtrlSetColor($CloseLab, 0x40BB40)
            GUICtrlSetFont($CloseLab, 12, 800, 0)
            $CLFlg = Not $CLFlg; outcome True
        Case $id <> $CloseLab And $CLFlg; Not hover label & has hovered previously
            GUICtrlSetColor($CloseLab, 0x000000)
            GUICtrlSetFont($CloseLab, Default, 800, 4)
            $CLFlg = Not $CLFlg; outcome False
        Case $msg = $CloseLab; Clicked label
            MsgBox(0, "", "Label Pressed")
    EndSelect
 
 WEnd
 
; From GUICtrlSetOnHover_UDF.au3
 Func _ControlGetHovered()
    Local $iRet = DllCall("user32.dll", "int", "WindowFromPoint", _
            "long", MouseGetPos(0), _
            "long", MouseGetPos(1))
    $iRet = DllCall("user32.dll", "int", "GetDlgCtrlID", "hwnd", $iRet[0])
    Return $iRet[0]
 EndFunc  ;==>_ControlGetHovered
;
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...