BlueSkyMemory Posted April 13, 2020 Share Posted April 13, 2020 expandcollapse popup#include-once #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> ; #VARIABLES# =================================================================================================================== ; =============================================================================================================================== Global $mCtrl_Hover[] $mCtrl_Hover['Old'] = '' $mCtrl_Hover['LastDown'] = False ;When mouse is down, record the ctrl to check the up ctrl is the previous one ; #FUNCTION# ==================================================================================================================== ; Name...........: _GUICtrlOnHover_Register ; Description ...: Registers a function to be called when GUI elements been hovered. ; Syntax.........: _GUICtrlOnHover_Register($idCtrl [, $sHover_Func= -1 [, $sLeave_Func=-1 [, $sPrimaryDown_Func=-1 [, $sPrimaryUp_Func=-1]]]]) Func _GUICtrlOnHover_Register($idCtrl, $sHover_Func = -1, $sLeave_Func = -1, $sPrimaryDown_Func = -1, $sPrimaryUp_Func = -1) If $idCtrl = -1 Then $idCtrl = _WinAPI_GetDlgCtrlID(GUICtrlGetHandle(-1)) If $sHover_Func <> -1 Then _NewMap($mCtrl_Hover, $idCtrl, 'Hover', $sHover_Func) If $sLeave_Func <> -1 Then _NewMap($mCtrl_Hover, $idCtrl, 'Leave', $sLeave_Func) If $sPrimaryDown_Func <> -1 Then _NewMap($mCtrl_Hover, $idCtrl, 'PrimaryDown', $sPrimaryDown_Func) If $sPrimaryUp_Func <> -1 Then _NewMap($mCtrl_Hover, $idCtrl, 'PrimaryUp', $sPrimaryUp_Func) _NewMap($mCtrl_Hover, $idCtrl, 'IsHover', False) ;When mouse is hovering the ctrl, do not call Hover Func when the mouse moving on it. If Not MapExists($mCtrl_Hover[$idCtrl], 'IsRegistered') Then Local $hProcNew = DllCallbackRegister("_GUICtrlOnHover__CallBack", "int", "hwnd;uint;uint;dword") $mCtrl_Hover['Old'] = _WinAPI_SetWindowLong(GUICtrlGetHandle($idCtrl), $GWL_WNDPROC, DllCallbackGetPtr($hProcNew)) _NewMap($mCtrl_Hover, $idCtrl, 'IsRegistered', True, False) EndIf EndFunc ;==>_GUICtrlOnHover_Register Func _GUICtrlOnHover__CallBack($hWnd, $uiMsg, $wParam, $lParam) Local $iCtrl = _WinAPI_GetDlgCtrlID($hWnd) Switch $uiMsg Case $WM_LBUTTONDOWN ;PrimaryDown $mCtrl_Hover['LastDown'] = $iCtrl If MapExists($mCtrl_Hover[$iCtrl], 'PrimaryDown') Then Call($mCtrl_Hover[$iCtrl]['PrimaryDown'], $iCtrl) EndIf Case $WM_LBUTTONUP ;PrimaryUp If MapExists($mCtrl_Hover[$iCtrl], 'PrimaryUp') And $iCtrl = $mCtrl_Hover['LastDown'] Then Call($mCtrl_Hover[$iCtrl]['PrimaryUp'], $iCtrl) EndIf $mCtrl_Hover['LastDown'] = False Case $WM_MOUSEHOVER ;Hover If MapExists($mCtrl_Hover[$iCtrl], 'Hover') And Not $mCtrl_Hover[$iCtrl]['IsHover'] Then $mCtrl_Hover[$iCtrl]['IsHover'] = True Call($mCtrl_Hover[$iCtrl]['Hover'], $iCtrl) EndIf Case $WM_MOUSELEAVE ;Leave If MapExists($mCtrl_Hover[$iCtrl], 'Leave') Then $mCtrl_Hover[$iCtrl]['IsHover'] = False Call($mCtrl_Hover[$iCtrl]['Leave'], $iCtrl) EndIf Case $WM_MOUSEMOVE ;Move If Not $mCtrl_Hover[$iCtrl]['IsHover'] Then _GUICtrlOnHover__TrackMouseEvent($hWnd, BitOR($TME_HOVER, $TME_LEAVE), 1) ;Triggers a hover/leave message EndSwitch Return _WinAPI_CallWindowProc($mCtrl_Hover['Old'], $hWnd, $uiMsg, $wParam, $lParam) EndFunc ;==>_GUICtrlOnHover__CallBack Func _GUICtrlOnHover__TrackMouseEvent($hWnd, $iFlags, $iTime) Local $tTME = DllStructCreate('dword;dword;hwnd;dword') DllStructSetData($tTME, 1, DllStructGetSize($tTME)) DllStructSetData($tTME, 2, $iFlags) DllStructSetData($tTME, 3, $hWnd) DllStructSetData($tTME, 4, $iTime) Local $aRet = DllCall('user32.dll', 'bool', 'TrackMouseEvent', 'struct*', $tTME) If @error Then Return SetError(@error, @extended, 0) Return $aRet[0] EndFunc ;==>_GUICtrlOnHover__TrackMouseEvent Only can be run in AutoIt Beta :) I use _WinAPI_SetWindowLong to response to hover messages, but it is too slow. Is there anyone can give some advice? Link to comment Share on other sites More sharing options...
HenryJiu Posted April 13, 2020 Share Posted April 13, 2020 Why hover to change color? Link to comment Share on other sites More sharing options...
BlueSkyMemory Posted April 13, 2020 Author Share Posted April 13, 2020 (edited) Yes, and other events. Edited April 13, 2020 by Jos Link to comment Share on other sites More sharing options...
HenryJiu Posted April 13, 2020 Share Posted April 13, 2020 (edited) But it is not very slow! Why do you say it is very slow? Edited April 13, 2020 by Jos Link to comment Share on other sites More sharing options...
BlueSkyMemory Posted April 13, 2020 Author Share Posted April 13, 2020 (edited) Compared to other softwares, the speed to change color seems to be a little slow...(I'm a completist lol) Edited April 13, 2020 by Jos Link to comment Share on other sites More sharing options...
HenryJiu Posted April 13, 2020 Share Posted April 13, 2020 (edited) OK!GoodBye! Edited April 13, 2020 by Jos Link to comment Share on other sites More sharing options...
HenryJiu Posted April 13, 2020 Share Posted April 13, 2020 (edited) Look! Edited April 13, 2020 by Jos Link to comment Share on other sites More sharing options...
BlueSkyMemory Posted April 13, 2020 Author Share Posted April 13, 2020 (edited) Thanks, I will study it. Edited April 13, 2020 by Jos Link to comment Share on other sites More sharing options...
Developers Jos Posted April 13, 2020 Developers Share Posted April 13, 2020 @HenryJiu, Could you please stop: Quoting the previous post (Counts for the both of you!). Only quote pieces when it makes sense! Posting in none English! It is fine you use Google translate, but we do not need this translation in this thread! Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
BlueSkyMemory Posted April 15, 2020 Author Share Posted April 15, 2020 By using SetWindowSubclass, this problem is solved. Thanks to everyone!😊 Link to comment Share on other sites More sharing options...
bladem2003 Posted July 22, 2022 Share Posted July 22, 2022 hi, where is the function _NewMap ? Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now