pixelsearch Posted December 29, 2024 Posted December 29, 2024 (edited) @Nine before ending this interesting thread, I have a last question if you don't mind. Please have a look at my last script in the preceding post (the one which uses _WinAPI_SetWindowSubclass to subclass the button) * The button seems correctly subclassed * There is no call to _WinAPI_TrackMouseEvent() in the script * $WM_MOUSELEAVE is triggered at the right moment. Now the question : why $WM_MOUSEHOVER is never triggered when we use this part of code instead : Func _BtnProc($hWnd, $iMsg, $wParam, $lParam, $IdSubclass, $dwRefData) Local Static $bHover, $iCounter = 0 Switch $iMsg Case $WM_MOUSEMOVE If Not $bHover Then GUICtrlSetImage($dwRefData, @ScriptDir & "\OK 52-51.bmp") $bHover = True EndIf Case $WM_MOUSEHOVER ; never triggered :( $iCounter += 1 ConsoleWrite("$WM_MOUSEHOVER : $iCounter = " & $iCounter & @crlf) Case $WM_MOUSELEAVE GUICtrlSetImage($dwRefData, @ScriptDir & "\Cancel 52-51.bmp") $bHover = False $iCounter += 1 ConsoleWrite("$WM_MOUSELEAVE : $iCounter = " & $iCounter & @crlf) EndSwitch Return _WinAPI_DefSubclassProc($hWnd, $iMsg, $wParam, $lParam) EndFunc ;==>_BtnProc I mean, when the button is subclassed, if $WM_MOUSELEAVE is triggered without the use of _WinAPI_TrackMouseEvent() , then why $WM_MOUSEHOVER doesn't react the same way ? Many thanks if you got the explanation... same thanks if you don't Edited December 29, 2024 by pixelsearch added to code the "never triggered" comment
Nine Posted December 29, 2024 Posted December 29, 2024 That is a mystery for me also. And that is even more strange because on some other controls like label, you need to track the LEAVE ! pixelsearch 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy
pixelsearch Posted December 29, 2024 Posted December 29, 2024 (edited) @Nine thanks for the test on a Label control. My goal was to get rid of $WM_MOUSEMOVE but apparently it can't be easily done... and maybe it's a good thing, let's see why. I just tested with a few other controls, like Input, List etc... and each one reacts differently. To test them, I started to modify 1 line in the script (without modifying the variable name or we'll never end) ; Local $idBtn = GUICtrlCreateButton("", 0, 0, 52, 51, $BS_BITMAP) ; Local $idBtn = GUICtrlCreateInput("", 0, 0, 52, 51) ; Local $idBtn = GUICtrlCreateList("", 0, 0, 52, 51) Local $idBtn = GUICtrlCreateLabel("", 0, 0, 52, 51) etc... and with this subclass function : Func _BtnProc($hWnd, $iMsg, $wParam, $lParam, $IdSubclass, $dwRefData) Local Static $bHover, $iCounter = 0, $sClassName = _WinAPI_GetClassName($g_hBtn) Switch $iMsg Case $WM_MOUSEMOVE _WinAPI_TrackMouseEvent($g_hBtn, $TME_HOVER + $TME_LEAVE, 10) ; 10ms Case $WM_MOUSEHOVER ; not 100% satisfying If Not $bHover Then If $sClassName = "Button" Then GUICtrlSetImage($dwRefData, @ScriptDir & "\OK 52-51.bmp") $iCounter += 1 ConsoleWrite("$WM_MOUSEHOVER : $iCounter = " & $iCounter & @crlf) $bHover = True EndIf Case $WM_MOUSELEAVE If $sClassName = "Button" Then GUICtrlSetImage($dwRefData, @ScriptDir & "\Cancel 52-51.bmp") $iCounter += 1 ConsoleWrite("$WM_MOUSELEAVE : $iCounter = " & $iCounter & @crlf) $bHover = False EndSwitch Return _WinAPI_DefSubclassProc($hWnd, $iMsg, $wParam, $lParam) EndFunc ;==>_BtnProc But results are not 100% satisfying because, as you indicated in this post, the 10ms wait parameter can create issues, like those displayed below in the Console, when you move quickly the mouse inside and outside the control, then several "MouseLeave" may be displayed instead of 1 only (this is a real Console display below) $WM_MOUSEHOVER : $iCounter = 1 $WM_MOUSELEAVE : $iCounter = 2 $WM_MOUSEHOVER : $iCounter = 3 $WM_MOUSELEAVE : $iCounter = 4 $WM_MOUSEHOVER : $iCounter = 5 $WM_MOUSELEAVE : $iCounter = 6 $WM_MOUSELEAVE : $iCounter = 7 <=== bad $WM_MOUSEHOVER : $iCounter = 8 $WM_MOUSELEAVE : $iCounter = 9 Changing 10ms to 1ms won't change anything and also changing it to 0ms will use the hovering system default (which is about 400ms I guess, not sure though) So my conclusion is to start scripting it as you initially did (e.g. without using $WM_MOUSEHOVER at all) but we need to add a call to _WinAPI_TrackMouseEvent(...$TME_LEAVE) in case the subclassed control requires it (your test with a Label control, mine with a List control which requires it too) . This is the resulting function : Func _BtnProc($hWnd, $iMsg, $wParam, $lParam, $IdSubclass, $dwRefData) Local Static $bHover, $iCounter = 0, $sClassName = _WinAPI_GetClassName($g_hBtn) Switch $iMsg Case $WM_MOUSEMOVE If Not $bHover Then If $sClassName = "Button" Then GUICtrlSetImage($dwRefData, @ScriptDir & "\OK 52-51.bmp") $iCounter += 1 ConsoleWrite("$WM_MOUSEMOVE : $iCounter = " & $iCounter & @crlf) $bHover = True EndIf _WinAPI_TrackMouseEvent($g_hBtn, $TME_LEAVE) Case $WM_MOUSELEAVE If $sClassName = "Button" Then GUICtrlSetImage($dwRefData, @ScriptDir & "\Cancel 52-51.bmp") $iCounter += 1 ConsoleWrite("$WM_MOUSELEAVE : $iCounter = " & $iCounter & @crlf) $bHover = False EndSwitch Return _WinAPI_DefSubclassProc($hWnd, $iMsg, $wParam, $lParam) EndFunc ;==>_BtnProc With this reworked function, we'll never find several followed "MouseLeave" in Console (tested) but only 1, preceded and followed by 1 "MouseMove", even if we move quickly the mouse inside/outside the control, and this, no matter the subclassed control is a Button, Label, Input, List control etc... I wonder if I should post a reworked script including these last modifications, but with this imaged button code, maybe it won't be clear. Anyway you got the idea. Hope it helps Edited December 29, 2024 by pixelsearch typo ioa747 1
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