Advertisement
wuuyi123

GUICtrlOnHover.au3

Sep 13th, 2017
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 23.33 KB | None | 0 0
  1. #Region Header
  2.  
  3. #include-once
  4.  
  5. #cs UDF Info
  6.  
  7.     Name.........:      GUICtrlOnHover.au3
  8.     Forum link...:      http://www.autoitscript.com/forum/index.php?s=&showtopic=55120
  9.     Author.......:      G.Sandler a.k.a MrCreatoR (CreatoR's Lab, www.creator-lab.ucoz.ru, www.autoit-script.ru)
  10.     Remarks......:
  11.                         1)  TreeView/ListView Items can not be set :(.
  12.                         2)  When the window is not active, the hover/leave hover functions will still called, but not when the window is disabled.
  13.                         3)  The hover/leave hover functions will be called even if the script is paused by such functions as MsgBox().
  14.                         4)  The $sHover_Func/$sLeaveHover_Func functions should not introduce significant delays in the main script,
  15.                             for example by calling functions like Sleep() or MsgBox().
  16.                         5) IMPORTANT!
  17.                             A)  Do not call _GUICtrl_OnHoverRegister inside $sHover_Func/$sLeaveHover_Func functions, it's not a good idea.
  18.  
  19.                             B)  This UDF registering WM_COMMAND and WM_LBUTTONDOWN window messages.
  20.                                 Please ensure that those messages are not used after including this library,
  21.                                 if they do, you will have to call __GUICtrl_SOH_WM_COMMAND and __GUICtrl_SOH_WM_LBUTTONDOWN inside those functions. Example:
  22.  
  23.                                 Func MY_WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
  24.                                     __GUICtrl_SOH_WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
  25.                                     ...
  26.                                 EndFunc
  27.  
  28.  
  29.     *** Version History ***
  30.  
  31.     [v2.0] - [09.06.2010]
  32.     * Fixed potential issue with calling $sPrimaryDownFunc function (first call was performed only after recieving WM_COMMAND message, wich is the control event).
  33.     * Fixed an issue with blocking the OnHover function - the OnLeaveHover function was not called untill the OnHover function was blocked.
  34.     * Fixed(?) (again) issue when the UDF is not working under 64-bit OS.
  35.     * Optimized internal "__GUICtrl_SOH_Call" function to work faster when calling parameters functions.
  36.  
  37.     [v1.9] - [21.05.2010]
  38.     * UDF library now compatible with AutoIt 3.3.6.1.
  39.     * UDF library renamed to GUICtrlOnHover.au3.
  40.     * Changed the main function name to _GUICtrl_OnHoverRegister, For backwards compatibility reasons, other (old) function names are still supported:
  41.         _GUICtrl_SetOnHover, GUICtrl_SetOnHover, GUICtrlSetOnHover, _GUICtrlSetOnHover
  42.  
  43.     * Fixed(?) issue when the UDF is not working under 64-bit OS.
  44.     * Global variables and internal functions renaming (for "cosmetic" reasons only).
  45.     * UDF's code is more readable now.
  46.  
  47.  
  48.     [v1.8] - [28.09.2009]
  49.     * Few Global variables now have more unique name.
  50.     * Fixed an issue with false calling of function on PrimaryDown event.
  51.         I.e when the user clicks on other place (not on the hovered control) and drag the cursor to the control, the PrimaryDown function was called.
  52.     * Due to (and as a result of) previous issue, the UDF now registering WM_COMMAND and WM_LBUTTONDOWN messages at first UDF call.
  53.  
  54.  
  55.     [v1.7] - [07.07.2009]
  56.     + Added _GUICtrl_SetHoverOnBackWindow...
  57.         Allows to set the hovering mode:
  58.                 $iSetBackWin = 1 (default) hovering process will proceed even when GUI is not active (in background).
  59.                 $iSetBackWin <> 1 hovering process will NOT proceed when GUI is not active.
  60.  
  61.  
  62.     [v1.6] - [12.06.2009]
  63.     * Now the UDF compatible with scripts (or other udfs) that uses OnAutoItExit function.
  64.         i.e: "OnAutoItExit" function that was *previously* set by user will be called as well.
  65.  
  66.     + Added new parameter $iKeepCall_Hover_Func. If this parameter = 1,
  67.         then the $sHover_Func function *Will* be called constantly untill the control is no longer been hovered
  68.         (default is 0, do not call the function constantly).
  69.     + Added new arguments to calling function...
  70.         The OnPrimaryDown/Up function now can recieve one more argument:
  71.             $iClickMode - Defines the Click mode (1 - Pressed, 2 - Released)
  72.  
  73.     * Changed return value - function will return 2 when $iCtrlID is redefined (ReSet, already exists in the controls list).
  74.     * Fixed incorrect documentation parts.
  75.     * Fixed "OnClick" handeling. When using multiple GUIs, the active gui was not recognized properly.
  76.     * Fixed(?) bug with "dimension range exceeded" when trying to UnSet a Control.
  77.  
  78.     [v1.5]
  79.     + Added AutoIt 3.2.10.0+ support, but 3.2.8.1 or less is dropped :( (due to lack of native CallBack functions).
  80.     + Added Primary Down and Primary Up support. Helping to handle with the buttons pressing.
  81.     + Added new arguments to calling function...
  82.         The OnHover function now can recieve two more arguments:
  83.             $iHoverMode - Defines the hover mode (1 - Hover, 2 - Leaves Hovering)
  84.             $hWnd_Hovered - Control Handle where the mouse is moved to (after hovering).
  85.  
  86.     * Almost all code of this UDF was rewritted.
  87.     * Now the main function name is _GUICtrl_SetOnHover(),
  88.         but for backwards compatibility reasons, other (old) function names are still supported.
  89.     * Fixed bug with hovering controls in other apps.
  90.     * Improvements in generaly, the UDF working more stable now.
  91.  
  92.     [v1.?]
  93.     * Beta changes, see "Forum link" for more details.
  94.  
  95.     [v1.0]
  96.     * First release.
  97.  
  98. #CE
  99.  
  100. #EndRegion Header
  101.  
  102. #Region Internal Global Variables
  103. Global $DLL_USER32 = DllOpen("user32.dll")
  104. If Not IsDeclared("DLL_USER32") Then $DLL_USER32 = DllOpen("user32.dll")
  105. Global $a__GUICtrl_SOH_Ctrls[1][1]
  106. Global $a__GUICtrl_SOH_LastHoveredElements[2]       = [-1, -1]
  107. Global $a__GUICtrl_SOH_LastHoveredElementsMark      = -1
  108. Global $h__GUICtrl_SOH_LastClickedElementMark       = -1
  109. Global $i__GUICtrl_SOH_CtrlsModified                = 0
  110. Global $i__GUICtrl_SOH_HoverOnBackWin               = 1
  111. Global $i__GUICtrl_SOH_LastPrimaryDownCtrlID        = 0
  112.  
  113. Global $p__GUICtrl_SOH_TimerProc                    = 0
  114. Global $i__GUICtrl_SOH_TimerID                      = 0
  115.  
  116. Global $s__GUICtrl_SOH_User32_Dll                   = $DLL_USER32   ;@SystemDir & "\User32.dll"
  117. Global $s__GUICtrl_SOH_OnExitFunc                   = ""
  118.  
  119. If @AutoItVersion < "3.3.2.0" Then
  120.     $s__GUICtrl_SOH_OnExitFunc = Execute('Opt("OnExitFunc", "__GUICtrl_SOH_Exit")')
  121. Else
  122.     Execute('OnAutoItExitRegister("__GUICtrl_SOH_Exit")')
  123. EndIf
  124.  
  125. Global Const $n__GUICtrl_SOH_WM_COMMAND             = 0x0111
  126. Global Const $n__GUICtrl_SOH_WM_LBUTTONDOWN         = 0x0201
  127.  
  128. #EndRegion Internal Global Variables
  129.  
  130. #Region Public Functions
  131.  
  132. ; #FUNCTION# ====================================================================================================
  133. ; Name...........:  _GUICtrl_OnHoverRegister
  134. ; Description....:  Registers a function to be called when GUI elements been hovered.
  135. ; Syntax.........:  _GUICtrl_OnHoverRegister($iCtrlID [, $sHover_Func="" [, $sLeaveHover_Func=-1 [, $sPrimaryDownFunc=-1 [, $sPrimaryUpFunc=-1 [, $iKeepCall_PrDn_Func=1 [, $iKeepCall_Hover_Func=0 ]]]]]])
  136. ;
  137. ; Parameters.....:  $iCtrlID              - The Ctrl ID to set hovering for (can be a -1 as indication to the last item created).
  138. ;
  139. ;                   $sHover_Func          - [Optional] Function to call when the mouse is hovering the control.
  140. ;                                             If this parameter passed as empty string (""),
  141. ;                                             then the specified CtrlID is UnSet from Hovering Handler list.
  142. ;
  143. ;                   $sLeaveHover_Func     - [Optional] Function to call when the mouse is leaving hovering the control
  144. ;                       (-1 no function used).
  145. ;                     * For both parameters, $sHover_FuncName and $sLeaveHover_FuncName,
  146. ;                       the specified function called with maximum 3 parameters:
  147. ;                                                     $iCtrlID      - CtrlID of hovered control.
  148. ;                                                     $iHoverMode   - Defines the hover mode (1 - Hover, 2 - Leaves Hovering).
  149. ;                                                     $hWnd_Hovered - Control Handle where the mouse is moved to (after hovering).
  150. ;
  151. ;                   $sPrimaryDownFunc     - [Optional] Function to call when Primary mouse button is *clicked* on the control.
  152. ;                       (-1 -> function is not called).
  153. ;
  154. ;                   $sPrimaryUpFunc       - [Optional] Function to call when Primary mouse button is *released* the control.
  155. ;                       (-1 -> function is not called).
  156. ;
  157. ;                     * For both parameters, $sPrimaryDownFunc and $sPrimaryUpFunc,
  158. ;                       the specified function called with maximum 2 parameters:
  159. ;                                                     $iCtrlID      - CtrlID of clicked control.
  160. ;                                                     $iClickMode   - Defines the click mode (1 - Pressed, 2 - Released).
  161. ;
  162. ;                   $iKeepCall_PrDn_Func  - [Optional] If this parameter < 1,
  163. ;                                            then the $sPrimaryDownFunc function will *Not* be called constantly untill
  164. ;                                            the primary mouse button is released (default behaviour - $iKeepCall_PrDn_Func = 1).
  165. ;
  166. ;                   $iKeepCall_Hover_Func - [Optional] If this parameter = 1,
  167. ;                                            then the $sHover_Func function *Will* be called constantly untill
  168. ;                                            the control is no longer been hovered (default behaviour - $iKeepCall_Hover_Func = 0).
  169. ;
  170. ; Return values..:  Success               - Returns 1 if the function registered succesefully.
  171. ;                                           When $iCtrlID is redefined (ReSet, already exists in the controls list), the return value is 2.
  172. ;                   Failure               - Set @error to 1 and return 0 if $iCtrlID is not a GUI Control Identifier.
  173. ;
  174. ; Author.........:  G.Sandler (a.k.a CreatoR), www.creator-lab.ucoz.ru, www.autoit-script.ru.
  175. ; Modified.......:
  176. ; Remarks........:  1) TreeView/ListView Items can not be set :(.
  177. ;                   2) When the window is not active, the hover/leave hover functions will still called, but not when the window is disabled.
  178. ;                   3) The hover/leave hover functions will be called even if the script is paused by such functions as MsgBox().
  179. ;                   4) The $sHover_Func/$sLeaveHover_Func functions should not introduce significant delays in the main script,
  180. ;                      for example by calling functions like Sleep() or MsgBox().
  181. ;                   5) IMPORTANT!
  182. ;                      A) Do not call _GUICtrl_OnHoverRegister inside $sHover_Func/$sLeaveHover_Func functions, it's not a good idea.
  183. ;
  184. ;                      B) This UDF registering WM_COMMAND and WM_LBUTTONDOWN window messages.
  185. ;                      Please ensure that those messages are not used after including this library,
  186. ;                      if they do, you will have to call __GUICtrl_SOH_WM_COMMAND and __GUICtrl_SOH_WM_LBUTTONDOWN inside those functions. Example:
  187. ;
  188. ;                           Func MY_WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
  189. ;                               __GUICtrl_SOH_WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
  190. ;                               ...
  191. ;                           EndFunc
  192. ;
  193. ; Related........:
  194. ; Link...........:  http://www.autoitscript.com/forum/index.php?s=&showtopic=55120
  195. ; Example........:  Yes.
  196. ; ===============================================================================================================
  197. Func _GUICtrl_OnHoverRegister($iCtrlID, $sHover_Func="", $sLeaveHover_Func=-1, $sPrimaryDownFunc=-1, $sPrimaryUpFunc=-1, $iKeepCall_PrDn_Func=1, $iKeepCall_Hover_Func=0)
  198.     Local $hCtrlID = GUICtrlGetHandle($iCtrlID)
  199.  
  200.     If Not $hCtrlID Then
  201.         Return SetError(1, 0, 0)
  202.     EndIf
  203.  
  204.     If $p__GUICtrl_SOH_TimerProc = 0 Then
  205.         $p__GUICtrl_SOH_TimerProc = DllCallbackRegister("__GUICtrl_SOH_CALLBACK", "none", "hwnd;int;uint_ptr;dword")
  206.         $i__GUICtrl_SOH_TimerID = DllCall($s__GUICtrl_SOH_User32_Dll, "int", "SetTimer", _
  207.             "hwnd", 0, "uint_ptr", Round(TimerInit()), "uint", 30, "ptr", DllCallbackGetPtr($p__GUICtrl_SOH_TimerProc))
  208.  
  209.         GUIRegisterMsg($n__GUICtrl_SOH_WM_COMMAND, "__GUICtrl_SOH_WM_COMMAND")
  210.         GUIRegisterMsg($n__GUICtrl_SOH_WM_LBUTTONDOWN, "__GUICtrl_SOH_WM_LBUTTONDOWN")
  211.  
  212.         If IsArray($i__GUICtrl_SOH_TimerID) Then
  213.             $i__GUICtrl_SOH_TimerID = $i__GUICtrl_SOH_TimerID[0]
  214.         EndIf
  215.     EndIf
  216.  
  217.     ;UnSet Hovering for specified control (remove control id from hovering checking process)
  218.     If $sHover_Func = "" And @NumParams <= 2 Then
  219.         Local $a__GUICtrl_SOH_Ctrls_Tmp[1][1]
  220.         Local $a__GUICtrl_SOH_Ctrls_Swap = $a__GUICtrl_SOH_Ctrls ;This one prevents a bug with "dimension range exceeded"
  221.  
  222.         For $i = 1 To $a__GUICtrl_SOH_Ctrls_Swap[0][0]
  223.             If $hCtrlID <> $a__GUICtrl_SOH_Ctrls_Swap[$i][0] Then
  224.                 $a__GUICtrl_SOH_Ctrls_Tmp[0][0] += 1
  225.                 ReDim $a__GUICtrl_SOH_Ctrls_Tmp[$a__GUICtrl_SOH_Ctrls_Tmp[0][0]+1][7]
  226.  
  227.                 $a__GUICtrl_SOH_Ctrls_Tmp[$a__GUICtrl_SOH_Ctrls_Tmp[0][0]][0] = $a__GUICtrl_SOH_Ctrls_Swap[$i][0]
  228.                 $a__GUICtrl_SOH_Ctrls_Tmp[$a__GUICtrl_SOH_Ctrls_Tmp[0][0]][1] = $a__GUICtrl_SOH_Ctrls_Swap[$i][1]
  229.                 $a__GUICtrl_SOH_Ctrls_Tmp[$a__GUICtrl_SOH_Ctrls_Tmp[0][0]][2] = $a__GUICtrl_SOH_Ctrls_Swap[$i][2]
  230.                 $a__GUICtrl_SOH_Ctrls_Tmp[$a__GUICtrl_SOH_Ctrls_Tmp[0][0]][3] = $a__GUICtrl_SOH_Ctrls_Swap[$i][3]
  231.                 $a__GUICtrl_SOH_Ctrls_Tmp[$a__GUICtrl_SOH_Ctrls_Tmp[0][0]][4] = $a__GUICtrl_SOH_Ctrls_Swap[$i][4]
  232.                 $a__GUICtrl_SOH_Ctrls_Tmp[$a__GUICtrl_SOH_Ctrls_Tmp[0][0]][5] = $a__GUICtrl_SOH_Ctrls_Swap[$i][5]
  233.                 $a__GUICtrl_SOH_Ctrls_Tmp[$a__GUICtrl_SOH_Ctrls_Tmp[0][0]][6] = $a__GUICtrl_SOH_Ctrls_Swap[$i][6]
  234.             EndIf
  235.         Next
  236.  
  237.         If $a__GUICtrl_SOH_Ctrls_Tmp[0][0] < 1 Then
  238.             __GUICtrl_SOH_ReleaseResources() ;Release the callbacks
  239.         Else
  240.             $i__GUICtrl_SOH_CtrlsModified = 1
  241.             $a__GUICtrl_SOH_Ctrls = $a__GUICtrl_SOH_Ctrls_Tmp
  242.         EndIf
  243.  
  244.         Return 1
  245.     EndIf
  246.  
  247.     ;Check if the hovering process already handle the passed CtrlID, if so, just assign new values (functions)
  248.     For $i = 1 To $a__GUICtrl_SOH_Ctrls[0][0]
  249.         If $hCtrlID = $a__GUICtrl_SOH_Ctrls[$i][0] Then
  250.             $a__GUICtrl_SOH_Ctrls[$i][0] = $hCtrlID
  251.             $a__GUICtrl_SOH_Ctrls[$i][1] = $sHover_Func
  252.             $a__GUICtrl_SOH_Ctrls[$i][2] = $sLeaveHover_Func
  253.             $a__GUICtrl_SOH_Ctrls[$i][3] = $sPrimaryDownFunc
  254.             $a__GUICtrl_SOH_Ctrls[$i][4] = $sPrimaryUpFunc
  255.             $a__GUICtrl_SOH_Ctrls[$i][5] = $iKeepCall_PrDn_Func
  256.             $a__GUICtrl_SOH_Ctrls[$i][6] = $iKeepCall_Hover_Func
  257.  
  258.             Return 2
  259.         EndIf
  260.     Next
  261.  
  262.     $a__GUICtrl_SOH_Ctrls[0][0] += 1
  263.     ReDim $a__GUICtrl_SOH_Ctrls[$a__GUICtrl_SOH_Ctrls[0][0]+1][7]
  264.  
  265.     $a__GUICtrl_SOH_Ctrls[$a__GUICtrl_SOH_Ctrls[0][0]][0] = $hCtrlID
  266.     $a__GUICtrl_SOH_Ctrls[$a__GUICtrl_SOH_Ctrls[0][0]][1] = $sHover_Func
  267.     $a__GUICtrl_SOH_Ctrls[$a__GUICtrl_SOH_Ctrls[0][0]][2] = $sLeaveHover_Func
  268.     $a__GUICtrl_SOH_Ctrls[$a__GUICtrl_SOH_Ctrls[0][0]][3] = $sPrimaryDownFunc
  269.     $a__GUICtrl_SOH_Ctrls[$a__GUICtrl_SOH_Ctrls[0][0]][4] = $sPrimaryUpFunc
  270.     $a__GUICtrl_SOH_Ctrls[$a__GUICtrl_SOH_Ctrls[0][0]][5] = $iKeepCall_PrDn_Func
  271.     $a__GUICtrl_SOH_Ctrls[$a__GUICtrl_SOH_Ctrls[0][0]][6] = $iKeepCall_Hover_Func
  272.  
  273.     Return 1
  274. EndFunc
  275.  
  276. ;Set the hovering mode:
  277. ;                      $iSetBackWin = 1 (default) hovering process will proceed even when GUI is not active (in background).
  278. ;                      $iSetBackWin <> 1 hovering process will NOT proceed when GUI is not active.
  279. Func _GUICtrl_SetHoverOnBackWindow($iSetBackWin)
  280.     $i__GUICtrl_SOH_HoverOnBackWin = Number($iSetBackWin = 1)
  281. EndFunc
  282.  
  283. #EndRegion Public Functions
  284.  
  285. #Region Backwards Compatibility Functions
  286.  
  287. ;Backwards compatibility function #1
  288. Func _GUICtrl_SetOnHover($iCtrlID, $sHover_Func="", $sLeaveHover_Func=-1, $sPrimaryDownFunc=-1, $sPrimaryUpFunc=-1, $iKeepCall_PrDn_Func=1, $iKeepCall_Hover_Func=0)
  289.     _GUICtrl_OnHoverRegister($iCtrlID, $sHover_Func, $sLeaveHover_Func, $sPrimaryDownFunc, $sPrimaryUpFunc, $iKeepCall_PrDn_Func, $iKeepCall_Hover_Func)
  290. EndFunc
  291.  
  292. ;Backwards compatibility function #2
  293. Func GUICtrl_SetOnHover($iCtrlID, $sHover_Func="", $sLeaveHover_Func=-1, $sPrimaryDownFunc=-1, $sPrimaryUpFunc=-1, $iKeepCall_PrDn_Func=1, $iKeepCall_Hover_Func=0)
  294.     _GUICtrl_OnHoverRegister($iCtrlID, $sHover_Func, $sLeaveHover_Func, $sPrimaryDownFunc, $sPrimaryUpFunc, $iKeepCall_PrDn_Func, $iKeepCall_Hover_Func)
  295. EndFunc
  296.  
  297. ;Backwards compatibility function #3
  298. Func GUICtrlSetOnHover($iCtrlID, $sHover_Func="", $sLeaveHover_Func=-1, $sPrimaryDownFunc=-1, $sPrimaryUpFunc=-1, $iKeepCall_PrDn_Func=1, $iKeepCall_Hover_Func=0)
  299.     _GUICtrl_OnHoverRegister($iCtrlID, $sHover_Func, $sLeaveHover_Func, $sPrimaryDownFunc, $sPrimaryUpFunc, $iKeepCall_PrDn_Func, $iKeepCall_Hover_Func)
  300. EndFunc
  301.  
  302. ;Backwards compatibility function #4
  303. Func _GUICtrlSetOnHover($iCtrlID, $sHover_Func="", $sLeaveHover_Func=-1, $sPrimaryDownFunc=-1, $sPrimaryUpFunc=-1, $iKeepCall_PrDn_Func=1, $iKeepCall_Hover_Func=0)
  304.     _GUICtrl_OnHoverRegister($iCtrlID, $sHover_Func, $sLeaveHover_Func, $sPrimaryDownFunc, $sPrimaryUpFunc, $iKeepCall_PrDn_Func, $iKeepCall_Hover_Func)
  305. EndFunc
  306.  
  307. #EndRegion Backwards Compatibility Functions
  308.  
  309. #Region Internal Functions
  310.  
  311. ;CallBack function to handle the hovering process
  312. Func __GUICtrl_SOH_CALLBACK($hWnd, $uiMsg, $idEvent, $dwTime)
  313.     $i__GUICtrl_SOH_CtrlsModified = 0
  314.  
  315.     If $a__GUICtrl_SOH_Ctrls[0][0] < 1 Then
  316.         Return
  317.     EndIf
  318.  
  319.     If $i__GUICtrl_SOH_HoverOnBackWin Then
  320.         Local $iControl_Hovered = __GUICtrl_SOH_ControlGetHovered()
  321.     Else
  322.         Local $iControl_Hovered = GUIGetCursorInfo()
  323.  
  324.         If Not IsArray($iControl_Hovered) Then
  325.             Return
  326.         EndIf
  327.  
  328.         $iControl_Hovered = GUICtrlGetHandle($iControl_Hovered[4])
  329.     EndIf
  330.  
  331.     Local $sCheck_LHE = $a__GUICtrl_SOH_LastHoveredElements[1]
  332.     Local $iCheck_LCEM = $h__GUICtrl_SOH_LastClickedElementMark
  333.     Local $iCtrlID
  334.  
  335.     ;Leave Hovering Process and reset variables
  336.     If Not $iControl_Hovered Or ($sCheck_LHE <> -1 And $iControl_Hovered <> $sCheck_LHE) Then
  337.         If $a__GUICtrl_SOH_LastHoveredElementsMark = -1 Then
  338.             Return
  339.         EndIf
  340.  
  341.         Local $a__Tmp_GUICtrl_SOH_LastHoveredElements[2] = [$a__GUICtrl_SOH_LastHoveredElements[0], $a__GUICtrl_SOH_LastHoveredElements[1]]
  342.  
  343.         $a__GUICtrl_SOH_LastHoveredElements[0] = -1
  344.         $a__GUICtrl_SOH_LastHoveredElements[1] = -1
  345.         $a__GUICtrl_SOH_LastHoveredElementsMark = -1
  346.         $h__GUICtrl_SOH_LastClickedElementMark = -1
  347.  
  348.         If $a__Tmp_GUICtrl_SOH_LastHoveredElements[0] <> -1 Then
  349.             $iCtrlID = DllCall($s__GUICtrl_SOH_User32_Dll, "int", "GetDlgCtrlID", "hwnd", $a__Tmp_GUICtrl_SOH_LastHoveredElements[1])
  350.  
  351.             If IsArray($iCtrlID) Then
  352.                 $iCtrlID = $iCtrlID[0]
  353.             EndIf
  354.  
  355.             ;2 is the indicator of OnLeavHover process
  356.             __GUICtrl_SOH_Call($a__Tmp_GUICtrl_SOH_LastHoveredElements[0], $iCtrlID, 2, $iControl_Hovered)
  357.         EndIf
  358.     Else ;Hovering Process, Primary Down/Up handler, and set $a__GUICtrl_SOH_LastHoveredElements
  359.         If $i__GUICtrl_SOH_CtrlsModified = 1 Then
  360.             $i__GUICtrl_SOH_CtrlsModified = 0
  361.             Return
  362.         EndIf
  363.  
  364.         Local $iUbound = UBound($a__GUICtrl_SOH_Ctrls)-1
  365.  
  366.         For $i = 1 To $a__GUICtrl_SOH_Ctrls[0][0]
  367.             If $i > $iUbound Then
  368.                 ExitLoop
  369.             EndIf
  370.  
  371.             If $a__GUICtrl_SOH_Ctrls[$i][0] = $iControl_Hovered Then
  372.                 $iCtrlID = DllCall($s__GUICtrl_SOH_User32_Dll, "int", "GetDlgCtrlID", "hwnd", $iControl_Hovered)
  373.  
  374.                 If IsArray($iCtrlID) Then
  375.                     $iCtrlID = $iCtrlID[0]
  376.                 EndIf
  377.  
  378.                 ;Primary Down/Up handler
  379.                 If ($a__GUICtrl_SOH_Ctrls[$i][3] <> "" Or $a__GUICtrl_SOH_Ctrls[$i][4] <> "") And ($iCheck_LCEM = -1 Or $iCheck_LCEM = $iControl_Hovered) Then
  380.                     Local $aCursorInfo = 0
  381.                     Local $hParent_Wnd = DllCall($s__GUICtrl_SOH_User32_Dll, "hwnd", "GetParent", "hwnd", $iControl_Hovered)
  382.  
  383.                     If Not @error And IsArray($hParent_Wnd) Then
  384.                         $hParent_Wnd = $hParent_Wnd[0]
  385.                         $aCursorInfo = GUIGetCursorInfo($hParent_Wnd)
  386.                     Else
  387.                         $aCursorInfo = GUIGetCursorInfo()
  388.                     EndIf
  389.  
  390.                     If IsArray($aCursorInfo) Then
  391.                         ;Primary Down...
  392.                         ;* First condition is to prevent function call when holding down m.button from other control
  393.                         ;* Last condition is to Prevent/Allow multiple function call
  394.                         ;(depending on $iKeepCall_PrDn_Func param).
  395.                         If ($i__GUICtrl_SOH_LastPrimaryDownCtrlID = $iControl_Hovered Or $i__GUICtrl_SOH_LastPrimaryDownCtrlID = 0) And WinActive($hParent_Wnd) And _
  396.                             $aCursorInfo[2] = 1 And $a__GUICtrl_SOH_Ctrls[$i][3] <> -1 And _
  397.                             (($a__GUICtrl_SOH_Ctrls[$i][5] < 1 And $iCheck_LCEM <> $iControl_Hovered) Or $a__GUICtrl_SOH_Ctrls[$i][5] > 0) Then
  398.  
  399.                             ;1 is the indicator of Primary*Down* event
  400.                             __GUICtrl_SOH_Call($a__GUICtrl_SOH_Ctrls[$i][3], $iCtrlID, 1)
  401.  
  402.                             $h__GUICtrl_SOH_LastClickedElementMark = $iControl_Hovered
  403.                         ;Primary Up
  404.                         ElseIf $aCursorInfo[2] = 0 And $a__GUICtrl_SOH_Ctrls[$i][4] <> -1 And $iCheck_LCEM = $iControl_Hovered Then
  405.                             ;2 is the indicator of Primary*Up* event
  406.                             __GUICtrl_SOH_Call($a__GUICtrl_SOH_Ctrls[$i][4], $iCtrlID, 2)
  407.  
  408.                             $h__GUICtrl_SOH_LastClickedElementMark = -1
  409.                         EndIf
  410.                     EndIf
  411.                 EndIf
  412.  
  413.                 If $i__GUICtrl_SOH_CtrlsModified = 1 Then
  414.                     ExitLoop
  415.                 EndIf
  416.  
  417.                 If $a__GUICtrl_SOH_Ctrls[$i][6] < 1 And $a__GUICtrl_SOH_LastHoveredElementsMark = $a__GUICtrl_SOH_Ctrls[$i][0] Then
  418.                     ExitLoop
  419.                 Else
  420.                     $a__GUICtrl_SOH_LastHoveredElementsMark = $a__GUICtrl_SOH_Ctrls[$i][0]
  421.                 EndIf
  422.  
  423.                 If $a__GUICtrl_SOH_Ctrls[$i][2] <> -1 Then
  424.                     $a__GUICtrl_SOH_LastHoveredElements[0] = $a__GUICtrl_SOH_Ctrls[$i][2]
  425.                     $a__GUICtrl_SOH_LastHoveredElements[1] = $iControl_Hovered
  426.                 EndIf
  427.  
  428.                 __GUICtrl_SOH_Call($a__GUICtrl_SOH_Ctrls[$i][1], $iCtrlID, 1, 0) ;1 is the indicator of OnHover process
  429.  
  430.                 If $i__GUICtrl_SOH_CtrlsModified = 1 Then
  431.                     ExitLoop
  432.                 EndIf
  433.  
  434.                 ExitLoop
  435.             EndIf
  436.         Next
  437.     EndIf
  438.  
  439.     $i__GUICtrl_SOH_CtrlsModified = 0
  440. EndFunc
  441.  
  442. Func __GUICtrl_SOH_WM_COMMAND($hWndGUI, $MsgID, $WParam, $LParam)
  443.     $i__GUICtrl_SOH_LastPrimaryDownCtrlID = $LParam
  444. EndFunc
  445.  
  446. Func __GUICtrl_SOH_WM_LBUTTONDOWN($hWndGUI, $MsgID, $WParam, $LParam)
  447.     $i__GUICtrl_SOH_LastPrimaryDownCtrlID = 0
  448. EndFunc
  449.  
  450. ;Thanks to amel27 for that one!!!
  451. Func __GUICtrl_SOH_ControlGetHovered()
  452.     Local $iOld_Opt_MCM = Opt("MouseCoordMode", 1)
  453.     Local $tPoint = DllStructCreate("int X;int Y")
  454.     Local $aMPos = MouseGetPos()
  455.  
  456.     DllStructSetData($tPoint, "x", $aMPos[0])
  457.     DllStructSetData($tPoint, "y", $aMPos[1])
  458.  
  459.     Local $tPointCast = DllStructCreate("int64", DllStructGetPtr($tPoint))
  460.     Local $aRet = DllCall($s__GUICtrl_SOH_User32_Dll, "hwnd", "WindowFromPoint", "int64", DllStructGetData($tPointCast, 1))
  461.  
  462.     Opt("MouseCoordMode", $iOld_Opt_MCM)
  463.  
  464.     If @error Then
  465.         Return SetError(@error, @extended, 0)
  466.     EndIf
  467.  
  468.     Return $aRet[0]
  469. EndFunc
  470.  
  471. ;Call() function wrapper
  472. Func __GUICtrl_SOH_Call($sFunction, $sParam1="", $sParam2="", $sParam3="", $sParam4="", $sParam5="")
  473.     Local $iRet = Call($sFunction)
  474.  
  475.     If @error <> 0xDEAD Then
  476.         Return $iRet
  477.     EndIf
  478.  
  479.     $iRet = Call($sFunction, $sParam1)
  480.  
  481.     If @error <> 0xDEAD Then
  482.         Return $iRet
  483.     EndIf
  484.  
  485.     $iRet = Call($sFunction, $sParam1, $sParam2)
  486.  
  487.     If @error <> 0xDEAD Then
  488.         Return $iRet
  489.     EndIf
  490.  
  491.     $iRet = Call($sFunction, $sParam1, $sParam2, $sParam3)
  492.  
  493.     If @error <> 0xDEAD Then
  494.         Return $iRet
  495.     EndIf
  496.  
  497.     $iRet = Call($sFunction, $sParam1, $sParam2, $sParam3, $sParam4)
  498.  
  499.     If @error <> 0xDEAD Then
  500.         Return $iRet
  501.     EndIf
  502.  
  503.     $iRet = Call($sFunction, $sParam1, $sParam2, $sParam3, $sParam4, $sParam5)
  504.  
  505.     If @error <> 0xDEAD Then
  506.         Return $iRet
  507.     EndIf
  508.  
  509.     Return SetError(1, 0, 0)
  510. EndFunc
  511.  
  512. ;Release resources function
  513. Func __GUICtrl_SOH_ReleaseResources()
  514.     If $p__GUICtrl_SOH_TimerProc > 0 Then
  515.         DllCallbackFree($p__GUICtrl_SOH_TimerProc)
  516.     EndIf
  517.  
  518.     If $i__GUICtrl_SOH_TimerID > 0 Then
  519.         DllCall($s__GUICtrl_SOH_User32_Dll, "int", "KillTimer", "hwnd", 0, "uint_ptr", $i__GUICtrl_SOH_TimerID)
  520.     EndIf
  521.  
  522.     GUIRegisterMsg($n__GUICtrl_SOH_WM_COMMAND, "")
  523.     GUIRegisterMsg($n__GUICtrl_SOH_WM_LBUTTONDOWN, "")
  524.  
  525.     $p__GUICtrl_SOH_TimerProc = 0
  526.     $i__GUICtrl_SOH_TimerID = 0
  527. EndFunc
  528.  
  529. ;Release the CallBack resources when exit
  530. Func __GUICtrl_SOH_Exit()
  531.     If $s__GUICtrl_SOH_OnExitFunc <> "" Then
  532.         Call($s__GUICtrl_SOH_OnExitFunc)
  533.     EndIf
  534.  
  535.     __GUICtrl_SOH_ReleaseResources()
  536. EndFunc
  537.  
  538. #EndRegion Internal Functions
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement