Jump to content
Sign in to follow this  
MrCreatoR

GUICtrlSetOnHover UDF!

Recommended Posts

Just another (rare) problem i faced:

Multiple simultaneous calls of my hover functions in some cases. For example when I had a Weblink opened by ShellExec it would open it 2 or more times.

Fix would be:

Func __GUICtrl_SOH_CALLBACK($hWnd, $iMsg, $idEvent, $dwTime)
    #forceref $hWnd, $iMsg, $idEvent, $dwTime
    Local Static $iCallbackActive = 0
    If Not $iCallbackActive Then
        $iCallbackActive = 1

...

$i__GUICtrl_SOH_CtrlsModified = 0
        $iCallbackActive = 0
    EndIf
EndFunc

Share this post


Link to post
Share on other sites

This UDf unfortunately is not compatible with touch clicks ..

So for example if you register the PrimaryUpFunc it works fine for Mouse-Clicks but not if you "click" with your finger ..
I tried to solve this by using the WM_TOUCH message but this message unfortunately won't get executed when touching on a control ..

Is there any way to solve this problem?

Share this post


Link to post
Share on other sites

The problem is the below code freezes whenever I click the close button

#include <GUICtrlOnHover.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>

Opt("GUIOnEventMode", 1)

$MainScreen = GUICreate("", 300, 300, -1, -1, $WS_POPUP)

$TopBarLbl = GUICtrlCreateLabel("", 0, 0, 280, 20, -1, $GUI_WS_EX_PARENTDRAG)
GUICtrlSetBkColor(-1, 0x000000)

$MainScreenClose = GUICtrlCreateLabel("X", 280, 0, 20, 20, BitOR($SS_CENTER, $SS_CENTERIMAGE))
GUICtrlSetOnEvent(-1, "ExitAll")
GUICtrlSetBkColor(-1, 0x000000)
GUICtrlSetColor(-1, 0xFFFFFF)
_GUICtrl_OnHoverRegister($MainScreenClose, "SpecialHoverOnLabel", "SpecialHoverOnLabel")

GUISetState()

While 1
    Sleep(50)
WEnd

Func ExitAll()
    Exit
EndFunc   ;==>ExitAll

Func SpecialHoverOnLabel($iCtrlID, $iParam)
    GUICtrlSetBkColor($iCtrlID, ($iParam = 1) ? 0x2DA84C : 0x000000)
EndFunc   ;==>SpecialHoverOnLabel

Figured it out. The click event has to be specified in the Register func itself

#include <GUICtrlOnHover.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>

Opt("GUIOnEventMode", 1)

$MainScreen = GUICreate("", 300, 300, -1, -1, $WS_POPUP)

$TopBarLbl = GUICtrlCreateLabel("", 0, 0, 280, 20, -1, $GUI_WS_EX_PARENTDRAG)
GUICtrlSetBkColor(-1, 0x000000)

$MainScreenClose = GUICtrlCreateLabel("X", 280, 0, 20, 20, BitOR($SS_CENTER, $SS_CENTERIMAGE))
;GUICtrlSetOnEvent(-1, "ExitAll")
GUICtrlSetBkColor(-1, 0x000000)
GUICtrlSetColor(-1, 0xFFFFFF)
_GUICtrl_OnHoverRegister($MainScreenClose, "SpecialHoverOnLabel", "SpecialHoverOnLabel", "ExitAll")

GUISetState()

While 1
    Sleep(50)
WEnd

Func ExitAll()
    Exit
EndFunc   ;==>ExitAll

Func SpecialHoverOnLabel($iCtrlID, $iParam)
    GUICtrlSetBkColor($iCtrlID, ($iParam = 1) ? 0x2DA84C : 0x000000)
EndFunc   ;==>SpecialHoverOnLabel

 

Edited by siva1612
Posted the problem and soltion

Share this post


Link to post
Share on other sites
On 3/23/2017 at 9:10 PM, siva1612 said:

Figured it out. Please delete this post.

Firstly; typically the MODs don't get in the business of deleting posts.
Secondly; even if you solved it yourself, it may be useful for future readers to read the problem & your solution.

edit: user added problem and solution to his post ;)

Edited by spudw2k

Share this post


Link to post
Share on other sites

Hi all,

I know this UDF and the thread is older, but I'm using this UDF for so long now and it is the perfect way.

Mainly I use the UDF for hover effects on buttons, or labels, but here and there also for click events.

For a long time I have had the problem that smaller ChildGUIs, or PopUps that are only short to see (about 1-3 seconds screentime), sometimes do not display any controls.

The whole thing is very irregular, but occurs with me about in 3 of 5 cases.

Unfortunately my project is much too big, so I created a small demo where I can reproduce the problem on my site.

Unfortunately the problem occurs much less often in the demo than in my main project.

But when it occurs you can only see the background of the GUI, but no labels.

By the way, it only seems to occur if I have registered at least one control with "_GUICtrl_OnHoverRegister()". If I have not registered a control, but included the UDF anyway, the error does not occur.

 

Can someone please look at this problem? Or does anyone have any idea how I could work around this problem? I don't want to do without the UDF.

Many thanks in advance. :)

borsTiHD

 

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
#include <WindowsConstants.au3>
#include <ColorConstants.au3>
#include <Misc.au3>

#include 'includes\GUICtrl_SetOnHover\GUICtrlOnHover.au3'                           ; https://www.autoitscript.com/forum/topic/55120-guictrlsetonhover-udf/

;GUI Options
Opt("GUIOnEventMode", 1)            ;OnEvent Mode wird aktiviert
Opt("GUIEventOptions", 1)           ;Ignoriert Windows Funktionen zum Minimieren und Schließen
Opt("GUIResizeMode", 802)           ;Sorgt dafür das die einzelnen GUI Elemente sich nicht in der Größe verändern
Opt("GUICoordMode", 1)              ;Benutzt feste Koordinaten für Elemente

Global $Hotkey = "^y"
HotKeySet($Hotkey, "SomeFunc")

Local $hGUI = GUICreate("Test", 800, 500)
Local $hLabel = GUICtrlCreateLabel("Test Label", 20, 15, 145, 30)
_GUICtrl_OnHoverRegister($hLabel, "_BTN_Hover_Func", "_BTN_Hover_Func", "_BTN_PrimaryDown_Func", "_BTN_PrimaryUp_Func")
GUISetState()

While 1
    Sleep(100)
WEnd

Func SomeFunc()

    send("^c")
    sleep(200)
    Local $sString = ClipGet()
    PopUp($sString)

EndFunc

Func PopUp($sString, $iFade = 200)
    Local Static $GUIFade = 0

    ConsoleWrite("$sString: " & $sString & @CRLF)

    ;Löscht GUI, sollte diese bereits existieren
    If WinExists($GUIFade) Then
        GUISwitch($GUIFade)
        GUIDelete($GUIFade)
    EndIf

    Local $MousePos = MouseGetPos()
    ;GUI
    $GUIFade = GUICreate("", 200, 40, $MousePos[0], $MousePos[1], $WS_POPUP)
    GUISetBkColor($COLOR_WHITE)
    GUICtrlCreateLabel($sString, 20, 15, 145, 30, 0x01)
    GUICtrlSetFont(-1, 10, -1, -1, "Arial Fett")
    GUISetState(@SW_SHOWNOACTIVATE, $GUIFade)
    WinSetOnTop($GUIFade, "", 1)
    Sleep($iFade)
    For $i = 1 To 18
        WinSetTrans($GUIFade, "", 255 - ($i * 10))
        WinSetOnTop($GUIFade, "", 1)
        Sleep(30)
    Next
    GUIDelete($GUIFade)
    GUISwitch($hGUI)
EndFunc   ;==>PopUp


; Button Hover/Leave
Func _BTN_Hover_Func($iCtrlID, $iParam) ; >> GUICtrlOnHover UDF
    
    ConsoleWrite("_BTN_Hover_Func() - Test " & @CRLF)
    Return True
EndFunc   ;==>_BTN_Hover_Func

; Button Mouseclick
Func _BTN_PrimaryDown_Func($iCtrlID) ; >> GUICtrlOnHover UDF

    ConsoleWrite("_BTN_PrimaryDown_Func() - Test " & @CRLF)
    Return True
EndFunc   ;==>_BTN_Hover_Func

; Button Mouseclick release
Func _BTN_PrimaryUp_Func($iCtrlID) ; >> GUICtrlOnHover UDF

    ConsoleWrite("_BTN_PrimaryUp_Func() - Test " & @CRLF)
    Return True
EndFunc   ;==>_BTN_Hover_Func

 

Edit: Ok... I looked at that again. With the GUICtrlOnHover_NoCallback.au3 the behavior does not happen.

In the past, I had the problems by changing between OnEvent and MsgLoop Mode. I bypassed this by only using the OnEvent mode, but this also causes me problems with for example _ArrayDisplay(). That's why I avoid switching between the two modes. But still I get, although I stay in one mode (OnEvent), the problems described above. :(

 

Edited by borsTiHD

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...