Jump to content

GUICtrlSetOnHover UDF!


MrCreatoR
 Share

Recommended Posts

Jex

If im use "Opt("MouseCoordMode", 0)" script not work true

Just add this to the top line of the function _ControlGetHovered():

Local $Old_Opt_MCM = Opt("MouseCoordMode", 1)

And this to the end (before Return $iRet[0]):

Opt("MouseCoordMode", $Old_Opt_MCM)

And all will work ok :P

Valery

works with AutoIt3 v3.2.9.13 (beta)

I think that all globals and the handler function are not needed there:

#include-once
Opt("MustDeclareVars", 1)
Opt("OnExitFunc", "CallBack_Exit")

;GUICtrlSetOnHover Initialize
Global $HOVER_CONTROLS_ARRAY[1][1]
Global $LAST_HOVERED_ELEMENT[2] = [-1, -1]
Global $LAST_HOVERED_ELEMENT_MARK = -1
Global $pTimerProc = DllCallbackRegister("CALLBACKPROC", "none", "hwnd;uint;uint;dword")
Global $uiTimer = DllCall("user32.dll", "uint", "SetTimer", "hwnd", 0, "uint", 0, "int", 10, "ptr", DllCallbackGetPtr($pTimerProc))
$uiTimer = $uiTimer[0]

Opt("MustDeclareVars", 0)

Func CALLBACKPROC($hWnd, $uiMsg, $idEvent, $dwTime)
    If UBound($HOVER_CONTROLS_ARRAY)-1 < 1 Then Return
    Local $ControlGetHovered = _ControlGetHovered()
    Local $sCheck_LHE = $LAST_HOVERED_ELEMENT[1]
    
    If $ControlGetHovered = 0 Or ($sCheck_LHE <> -1 And $ControlGetHovered <> $sCheck_LHE) Then
        If $LAST_HOVERED_ELEMENT_MARK = -1 Then Return
        If $LAST_HOVERED_ELEMENT[0] <> -1 Then Call($LAST_HOVERED_ELEMENT[0], $LAST_HOVERED_ELEMENT[1])
        $LAST_HOVERED_ELEMENT[0] = -1
        $LAST_HOVERED_ELEMENT[1] = -1
        $LAST_HOVERED_ELEMENT_MARK = -1
    Else
        For $i = 1 To $HOVER_CONTROLS_ARRAY[0][0]
            If $HOVER_CONTROLS_ARRAY[$i][0] = GUICtrlGetHandle($ControlGetHovered) Then
                If $LAST_HOVERED_ELEMENT_MARK = $HOVER_CONTROLS_ARRAY[$i][0] Then ExitLoop
                $LAST_HOVERED_ELEMENT_MARK = $HOVER_CONTROLS_ARRAY[$i][0]
                Call($HOVER_CONTROLS_ARRAY[$i][1], $ControlGetHovered)
                If $HOVER_CONTROLS_ARRAY[$i][2] <> -1 Then
                    $LAST_HOVERED_ELEMENT[0] = $HOVER_CONTROLS_ARRAY[$i][2]
                    $LAST_HOVERED_ELEMENT[1] = $ControlGetHovered
                EndIf
                ExitLoop
            EndIf
        Next
    EndIf
EndFunc

Func GUICtrlSetOnHover($CtrlID, $HoverFuncName, $LeaveHoverFuncName=-1)
    Local $Ubound = UBound($HOVER_CONTROLS_ARRAY)
    ReDim $HOVER_CONTROLS_ARRAY[$Ubound+1][3]
    $HOVER_CONTROLS_ARRAY[$Ubound][0] = GUICtrlGetHandle($CtrlID)
    $HOVER_CONTROLS_ARRAY[$Ubound][1] = $HoverFuncName
    $HOVER_CONTROLS_ARRAY[$Ubound][2] = $LeaveHoverFuncName
    $HOVER_CONTROLS_ARRAY[0][0] = $Ubound
EndFunc

;Thanks to amel27 for that one!!!
Func _ControlGetHovered()
    Local $Old_Opt_MCM = Opt("MouseCoordMode", 1)
    Local $iRet = DllCall("user32.dll", "int", "WindowFromPoint", _
        "long", MouseGetPos(0), _
        "long", MouseGetPos(1))
    $iRet = DllCall("user32.dll", "int", "GetDlgCtrlID", "hwnd", $iRet[0])
    Opt("MouseCoordMode", $Old_Opt_MCM)
    Return $iRet[0]
EndFunc

Func CallBack_Exit()
    DllCallbackFree($pTimerProc)
    DllCall("user32.dll", "int", "KillTimer", "hwnd", 0, "uint", $uiTimer)
EndFunc

Tell me please if this work, then i will put it into the first post as usage for AutoIt beta.

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

Hi...i think there is a problem if it`s over an image...the leave hover dosn`t work :P

Example:

$Pic1 = GUICtrlCreatePic("pic.jpg", 95, 0, 285, 75)
$Label = GUICtrlCreateLabel("Label", 186, 48, 13, 17)
GUICtrlSetOnHover($Yes, "Hover_Func", "Leave_Hover_Func")

Correct me if i`m wrong... ;)

BTW it`s awsome:D

Awww, You were ignored xD;;

Anyway,

$Pic1 = GUICtrlCreatePic("pic.jpg", 95, 0, 285, 75)
GUICtrlSetState(-1, $GUI_DISABLED)
$Label = GUICtrlCreateLabel("Label", 186, 48, 13, 17)
GUICtrlSetOnHover($Yes, "Hover_Func", "Leave_Hover_Func")
# MY LOVE FOR YOU... IS LIKE A TRUCK- #
Link to comment
Share on other sites

Ok, the UDF in my last post work perfectly in the final AutoIt Release (on the last beta actualy, but in the final AutoIt 3.2.10.0 there was no changes since then), now it available in the first post as addition UDF for 3.2.10.0 :P

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

So this works on every control that is OnEvent-able?

Not only :P see the GuiCtrlSetOnHover - Console + GUI Demo in the archive (attached to the first post).

But i think it will not work with TreeView/ListView and similar controls (items).

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

  • 4 weeks later...

For me it does not work on icons...

I tried it on a slider and it works perfect, but the same for icons does not work

It does not call the function:

Func Rate_GUI()
    Global $RateIcon[22]
    Global $RateGUI = XSkinGUICreate("PPlayer - Rate", 339+$factorX*2, 234+$factorY*2, $Skin_Folder,1,25,-1,-1,-1,$MainGUI)
    XSkinIcon($RateGUI,3,StringSplit("RateClose|RateClose|RateHelp","|"))
    $nr = 0
    For $x = 8 To 296 Step 32
        $nr += 1
        $RateIcon[$nr] = GUICtrlCreateIcon("resource\hovered.ico",-1, $x+$factorX, 120+$factorY, 32, 32, 0)
        GUICtrlSetOnHover($RateIcon[$nr],"RateOnHover","RateOffHover")
    Next
    For $x = 8 To 296 Step 32
        $nr += 1
        $RateIcon[$nr] = GUICtrlCreateIcon("resource\hovered.ico",-1, $x+$factorX, 152+$factorY, 32, 32, 0)
        GUICtrlSetOnHover($RateIcon[$nr],"RateOnHover","RateOffHover")
    Next
    Global $RateButton1 = GUICtrlCreateButton("Save", 104+$factorX, 192+$factorY, 113, 33, 0)
    GUICtrlSetOnEvent(-1,"RateSave")
    Global $RateLabel1 = GUICtrlCreateLabel("", 0+$factorX, 0+$factorY, 332, 116)
EndFunc   ;==>Rate_GUI

Func RateOnHover($Control)
    debug("test")
    $Hover = True
    For $i = 1 To 20
        If $Control == $RateIcon[$i] Then $Hover = False
        If $Hover Then
            GUICtrlSetImage($RateIcon[$i],"resource\hovered.ico")
        Else
            GUICtrlSetImage($RateIcon[$i],"resource\unhovered.ico")
        EndIf
    Next
EndFunc

Func RateOffHover($Control)
    
EndFunc

Any idea?

Edit: nvm it works perfect...

Koda adds same stupid 0's as style on Buttons...

Edited by Pascal257
Link to comment
Share on other sites

  • 3 weeks later...
  • 2 months later...
  • 1 month later...

TH UDF has sometimes a problem with Multiple Windows. Sometimes, you can hover the Controls of one Window by pointing on some Controls on an other window. As fix, the CTRLID should be used on a very late state, and before you should use the HWND. Fixed UDf:

#include-once
Opt("MustDeclareVars", 1)
Opt("OnExitFunc", "CallBack_Exit")

;GUICtrlSetOnHover Initialize
Global $HOVER_CONTROLS_ARRAY[1][1]
Global $LAST_HOVERED_ELEMENT[2] = [-1, -1]
Global $LAST_HOVERED_ELEMENT_MARK = -1
Global $pTimerProc = DllCallbackRegister("CALLBACKPROC", "none", "hwnd;uint;uint;dword")
Global $uiTimer = DllCall("user32.dll", "uint", "SetTimer", "hwnd", 0, "uint", 0, "int", 10, "ptr", DllCallbackGetPtr($pTimerProc))
$uiTimer = $uiTimer[0]

Opt("MustDeclareVars", 0)



;===============================================================================
;
; Function Name:    GUICtrlSetOnHover()
; Description:      Set function(s) to call when hovering/leave hovering GUI elements.
; Parameter(s):     $CtrlID - The Ctrl ID to set hovering for (can be a -1 as indication to the last item created).
;                   $HoverFuncName - Function to call when the mouse is hovering the control.
;                   $LeaveHoverFuncName - [Optional] Function to call when the mouse is leaving hovering the control
;                       (-1 no function used).
;
; Return Value(s):  Always returns 1 regardless of success.
; Requirement(s):   AutoIt 3.2.10.0
; Note(s):          1) TreeView/ListView Items can not be set :(.
;                   2) When the window is not active, the hover/leave hover functions will still called,
;                      but not when the window is disabled.
;                   3) The hover/leave hover functions will be called even if the script is paused by such functions as MsgBox().
; Author(s):        G.Sandler (a.k.a CreatoR).
;
;===============================================================================
Func GUICtrlSetOnHover($CtrlID, $HoverFuncName, $LeaveHoverFuncName=-1)
    Local $Ubound = UBound($HOVER_CONTROLS_ARRAY)
    ReDim $HOVER_CONTROLS_ARRAY[$Ubound+1][3]
    $HOVER_CONTROLS_ARRAY[$Ubound][0] = GUICtrlGetHandle($CtrlID)
    $HOVER_CONTROLS_ARRAY[$Ubound][1] = $HoverFuncName
    $HOVER_CONTROLS_ARRAY[$Ubound][2] = $LeaveHoverFuncName
    $HOVER_CONTROLS_ARRAY[0][0] = $Ubound
EndFunc

;CallBack function to handle the hovering process
Func CALLBACKPROC($hWnd, $uiMsg, $idEvent, $dwTime)
    If UBound($HOVER_CONTROLS_ARRAY)-1 < 1 Then Return
    Local $ControlGetHovered = _ControlGetHoveredHwnd()
    Local $sCheck_LHE = $LAST_HOVERED_ELEMENT[1]
    
    If $ControlGetHovered = 0 Or ($sCheck_LHE <> -1 And $ControlGetHovered <> $sCheck_LHE) Then
        If $LAST_HOVERED_ELEMENT_MARK = -1 Then Return
        If $LAST_HOVERED_ELEMENT[0] <> -1 Then Call($LAST_HOVERED_ELEMENT[0], _ControlGetID($LAST_HOVERED_ELEMENT[1]))
        $LAST_HOVERED_ELEMENT[0] = -1
        $LAST_HOVERED_ELEMENT[1] = -1
        $LAST_HOVERED_ELEMENT_MARK = -1
    Else
        For $i = 1 To $HOVER_CONTROLS_ARRAY[0][0]
            If $HOVER_CONTROLS_ARRAY[$i][0] = $ControlGetHovered Then
                If $LAST_HOVERED_ELEMENT_MARK = $HOVER_CONTROLS_ARRAY[$i][0] Then ExitLoop
                $LAST_HOVERED_ELEMENT_MARK = $HOVER_CONTROLS_ARRAY[$i][0]
                Call($HOVER_CONTROLS_ARRAY[$i][1], _ControlGetID($ControlGetHovered))
                If $HOVER_CONTROLS_ARRAY[$i][2] <> -1 Then
                    $LAST_HOVERED_ELEMENT[0] = $HOVER_CONTROLS_ARRAY[$i][2]
                    $LAST_HOVERED_ELEMENT[1] = $ControlGetHovered
                EndIf
                ExitLoop
            EndIf
        Next
    EndIf
EndFunc

Func _ControlGetID($ControlGetHovered)
    Local $ControlGetHoveredID = DllCall("user32.dll", "int", "GetDlgCtrlID", "hwnd", $ControlGetHovered)
    If @error Then Return 
    Return $ControlGetHoveredID[0]
EndFunc

;Thanks to amel27 for that one!!!
Func _ControlGetHoveredHwnd()
    Local $mouse = MouseGetPos()
    Local $iRet = DllCall("user32.dll", "hwnd", "WindowFromPoint", _
        "long", $mouse[0], _
        "long", $mouse[1])
    Return $iRet[0]
EndFunc

;Release the CallBack resources
Func CallBack_Exit()
    DllCallbackFree($pTimerProc)
    DllCall("user32.dll", "int", "KillTimer", "hwnd", 0, "uint", $uiTimer)
EndFunc

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

  • 3 weeks later...

Well I tried the original sample code and it works. So I copied my code parts by parts and now my code works. I don't know what I did to make it not working... but now it works. ProgAndy's also works. Thanks!

However, it doesn't seem to work when I put it on pic or input... Only button then?

Link to comment
Share on other sites

  • 2 weeks later...

However, it doesn't seem to work when I put it on pic or input... Only button then?

It works with pics also, see this example:

#include <GUICtrlSetOnHover_UDF.au3>
#include <GuiConstantsEx.au3>

Global $Pic1 = @Systemdir & "\oobe\images\hand1.gif"
Global $Pic2 = @Systemdir & "\oobe\images\hand2.gif"

$Gui = GUICreate("GuiCtrlSetOnHover - Hand Demo", 280, 200)

$Hand_Pic = GUICtrlCreatePic($Pic1, 55, 35, 180, 120)
GUICtrlSetOnHover(-1, "Hover_Func", "Leave_Hover_Func")

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func Hover_Func($iCtrlID)
    Switch $iCtrlID
        Case $Hand_Pic
            GUICtrlSetImage($iCtrlID, $Pic2)
    EndSwitch
EndFunc

Func Leave_Hover_Func($iCtrlID)
    Switch $iCtrlID
        Case $Hand_Pic
            GUICtrlSetImage($iCtrlID, $Pic1)
    EndSwitch
EndFunc

Does it work under 3.2.12.0 ?

Yes it works.

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

Hi MrCreatoR i wanned to say that i`ve made some modifications to your UDF and added the 3rd state of a button. The code is below...It needs some improvement but...i didn`t had the time...

Very nice, i liked the idea a lot! therfore i made an appropriate changes:

Experimental version:

* Added two more optional parameters; $sPrimaryDownFuncName and $sPrimaryUpFuncName.

- Now you can set "onclick" as well :)

Here is an example, the changed UDF itself and this example attached to the first post:

#include <GUICtrlSetOnHover_UDF.au3>
#include <GUIConstants.au3>
;

Global $PlayIsClicked   = False
Global $sImages_Path    = @ScriptDir & "\Images"

$Gui = GUICreate("GuiCtrlSetOnHover - onclick Hovering Demo", 280, 200)
GUISetBkColor(0xFFFFFF)

$Button = GUICtrlCreatePic($sImages_Path & "\btn0.jpg", 82, 24, 82, 24)
_GUICtrlSetOnHover(-1, "Hover_Func", "Leave_Hover_Func", "PrimaryDown_Func", "PrimaryUp_Func")

$Round = GUICtrlCreatePic($sImages_Path & "\round0.jpg", 82, 70, 150, 24)
_GUICtrlSetOnHover(-1, "Hover_Func", "Leave_Hover_Func", "PrimaryDown_Func", "PrimaryUp_Func")

$Pause = GUICtrlCreatePic($sImages_Path & "\pause0.jpg", 110, 100, 40, 40)
_GUICtrlSetOnHover(-1, "Hover_Func", "Leave_Hover_Func", "PrimaryDown_Func", "PrimaryUp_Func")

$Play = GUICtrlCreatePic($sImages_Path & "\play0.jpg", 70, 100, 40, 40)
_GUICtrlSetOnHover(-1, "Hover_Func", "Leave_Hover_Func", "PrimaryDown_Func", "PrimaryUp_Func")

GUISetState()

While 1
    $Msg = GUIGetMsg()
    
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
    
    If $PlayIsClicked Then
        $PlayIsClicked = False
        
        MsgBox(64, "", "You Clicked 'Play' Button")
    EndIf
WEnd

Func Hover_Func($iCtrlID)
    Switch $iCtrlID
        Case $Button
            GUICtrlSetImage($iCtrlID, $sImages_Path & "\btn1.jpg")
        Case $Round
            GUICtrlSetImage($iCtrlID, $sImages_Path & "\round1.jpg")
        Case $Pause
            GUICtrlSetImage($iCtrlID, $sImages_Path & "\pause1.jpg")
        Case $Play
            GUICtrlSetImage($iCtrlID, $sImages_Path & "\play1.jpg")
    EndSwitch
EndFunc

Func Leave_Hover_Func($iCtrlID)
    Switch $iCtrlID
        Case $Button
            GUICtrlSetImage($iCtrlID, $sImages_Path & "\btn0.jpg")
        Case $Round
            GUICtrlSetImage($iCtrlID, $sImages_Path & "\round0.jpg")
        Case $Pause
            GUICtrlSetImage($iCtrlID, $sImages_Path & "\pause0.jpg")
        Case $Play
            GUICtrlSetImage($iCtrlID, $sImages_Path & "\play0.jpg")
    EndSwitch
EndFunc

Func PrimaryDown_Func($iCtrlID)
    Switch $iCtrlID
        Case $Button
            GUICtrlSetImage($iCtrlID, $sImages_Path & "\btn2.jpg")
        Case $Round 
            GUICtrlSetImage($iCtrlID, $sImages_Path & "\round2.jpg")
        Case $Pause
            GUICtrlSetImage($iCtrlID, $sImages_Path & "\pause2.jpg")
        Case $Play
            GUICtrlSetImage($iCtrlID, $sImages_Path & "\play2.jpg")
            
            ;$PlayIsClicked = True
    EndSwitch
EndFunc

Func PrimaryUp_Func($iCtrlID)
    Switch $iCtrlID
        Case $Button
            GUICtrlSetImage($iCtrlID, $sImages_Path & "\btn1.jpg")
        Case $Round 
            GUICtrlSetImage($iCtrlID, $sImages_Path & "\round1.jpg")
        Case $Pause
            GUICtrlSetImage($iCtrlID, $sImages_Path & "\pause1.jpg")
        Case $Play
            GUICtrlSetImage($iCtrlID, $sImages_Path & "\play1.jpg")
            
            $PlayIsClicked = True
    EndSwitch
EndFunc

Works with 3.2.8.1/3.2.10.0/3.2.12.0, but for the two last can be (and needs to be) changed due to native CallBacks implementation.

BTW, the PrimaryDown/Up functions called even when you continueing to hovering the controls, until you decide where you want it :)

Edited by MrCreatoR

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

I tried to use it on a TreeViewItem, but no success, nothing happens, isn't it possible or am I doing something wrong ?

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <TreeViewConstants.au3>
#include <StaticConstants.au3>
#include "GUICtrlSetOnHover_UDF.au3"
Opt('MustDeclareVars', 1)

Example()

Func Example()
    Local $treeview, $generalitem, $displayitem, $aboutitem, $compitem
    Local $useritem, $resitem, $otheritem, $startlabel, $aboutlabel
    Local $compinfo, $togglebutton, $infobutton, $statebutton, $cancelbutton
    Local $msg, $item, $text, $hItem
    
    GUICreate("My GUI with treeview", 350, 215)

    $treeview = GUICtrlCreateTreeView(6, 6, 100, 150, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)
    $generalitem = GUICtrlCreateTreeViewItem("General", $treeview)
    GUICtrlSetColor(-1, 0x0000C0)
    $displayitem = GUICtrlCreateTreeViewItem("Display", $treeview)
    GUICtrlSetColor(-1, 0x0000C0)
    $aboutitem = GUICtrlCreateTreeViewItem("About", $generalitem)
    $compitem = GUICtrlCreateTreeViewItem("Computer", $generalitem)
    $useritem = GUICtrlCreateTreeViewItem("User", $generalitem)
    $resitem = GUICtrlCreateTreeViewItem("Resolution", $displayitem)
    $otheritem = GUICtrlCreateTreeViewItem("Other", $displayitem)
    GUICtrlSetOnHover($otheritem, "_ShowTrackComment", "_DontShowTrackComment")

    $startlabel = GUICtrlCreateLabel("TreeView Demo", 190, 90, 100, 20)
    $aboutlabel = GUICtrlCreateLabel("This little scripts demonstates the using of a treeview-control.", 190, 70, 100, 60)
    GUICtrlSetState(-1, $GUI_HIDE) ; Hides the "aboutlabel"-text during initialization
    $compinfo = GUICtrlCreateLabel("Name:" & @TAB & @ComputerName & @LF & "OS:" & @TAB & @OSVersion & @LF & "SP:" & @TAB & @OSServicePack, 120, 30, 200, 80)
    GUICtrlSetState(-1, $GUI_HIDE) ; Hides the "compinfo"-text during initialization

    GUICtrlCreateLabel("", 0, 170, 350, 2, $SS_SUNKEN)
    $togglebutton = GUICtrlCreateButton("&Toggle", 35, 185, 70, 20)
    $infobutton = GUICtrlCreateButton("&Info", 105, 185, 70, 20)
    $statebutton = GUICtrlCreateButton("Col./Exp.", 175, 185, 70, 20)
    $cancelbutton = GUICtrlCreateButton("&Cancel", 245, 185, 70, 20)

    GUICtrlSetState($generalitem, BitOR($GUI_EXPAND, $GUI_DEFBUTTON))   ; Expand the "General"-item and paint in bold
    GUICtrlSetState($displayitem, BitOR($GUI_EXPAND, $GUI_DEFBUTTON))   ; Expand the "Display"-item and paint in bold

    GUISetState()
    While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $cancelbutton Or $msg = $GUI_EVENT_CLOSE
                ExitLoop

            Case $msg = $togglebutton  ; Toggle the bold painting
                If BitAND(GUICtrlRead($generalitem), $GUI_DEFBUTTON) Then
                    GUICtrlSetState($generalitem, 0)
                    GUICtrlSetState($displayitem, 0)
                Else
                    GUICtrlSetState($generalitem, $GUI_DEFBUTTON)
                    GUICtrlSetState($displayitem, $GUI_DEFBUTTON)
                EndIf

            Case $msg = $infobutton
                $item = GUICtrlRead($treeview)   ; Get the controlID of the current selected treeview item
                If $item = 0 Then
                    MsgBox(64, "TreeView Demo", "No item currently selected")
                Else
                    $text = GUICtrlRead($item, 1); Get the text of the treeview item
                    If $text == "" Then
                        MsgBox(16, "Error", "Error while retrieving infos about item")
                    Else
                        MsgBox(64, "TreeView Demo", "Current item selected is: " & $text)
                    EndIf
                EndIf

            Case $msg = $statebutton
                $item = GUICtrlRead($treeview)
                If $item > 0 Then
                    $hItem = GUICtrlGetHandle($item)
                    DllCall("user32.dll", "int", "SendMessage", "hwnd", GUICtrlGetHandle($treeview), "int", $TVM_EXPAND, "int", $TVE_TOGGLE, "hwnd", $hItem)
                EndIf

            ; The following items will hide the other labels (1st and 2nd parameter) and then show the 'own' labels (3rd and 4th parameter)
            Case $msg = $generalitem
                GUIChangeItems($aboutlabel, $compinfo, $startlabel, $startlabel)

            Case $msg = $aboutitem
                GUICtrlSetState($compinfo, $GUI_HIDE)
                GUIChangeItems($startlabel, $startlabel, $aboutlabel, $aboutlabel)

            Case $msg = $compitem
                GUIChangeItems($startlabel, $aboutlabel, $compinfo, $compinfo)
        EndSelect
    WEnd

    GUIDelete()
EndFunc  ;==>Example

Func GUIChangeItems($hidestart, $hideend, $showstart, $showend)
    Local $idx

    For $idx = $hidestart To $hideend
        GUICtrlSetState($idx, $GUI_HIDE)
    Next
    For $idx = $showstart To $showend
        GUICtrlSetState($idx, $GUI_SHOW)
    Next
EndFunc  ;==>GUIChangeItems


Func _ShowTrackComment()
    Local $l_CursorInfo
    $l_CursorInfo = GUIGetCursorInfo ($TimeReporterGUI)
    Tooltip("test",$l_CursorInfo[0],$l_CursorInfo[0])
EndFunc
Func _DontShowTrackComment()
    Tooltip("")
EndFunc
Link to comment
Share on other sites

I tried to use it on a TreeViewItem, but no success, nothing happens, isn't it possible or am I doing something wrong ?

No, it's not will work on TreeView / ListView items.

In the UDF description i mention that:

Note(s):

1) TreeView/ListView Items can not be set :).

2) When the window is not active, the hover/leave hover functions will still called, but not when the window is disabled.

3) The hover/leave hover functions will be called even if the script is paused by such functions as MsgBox().

Edited by MrCreatoR

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

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...