nend Posted April 21, 2017 Posted April 21, 2017 (edited) Hi Guys, I'm trying to make a custom traysettooltip but I can't find a good way to know when the cursor is hover over and leave the tray icon. I'm trying to do this by $TRAY_EVENT_MOUSEOVER and use a timer but how can I recognise if the cursor is left the icon? This is what I have so far, but there has to be a betterway this isn't much reliable. expandcollapse popup#NoTrayIcon #include <TrayConstants.au3> Global $tray_tmr, $tray_pos, $tray_tmr, $tmr_notification, $notification Opt("TrayMenuMode", 3) TraySetToolTip(Chr("0")) Local $idExit = TrayCreateItem("Exit") TraySetState($TRAY_ICONSTATE_SHOW) ; Show the tray menu. While 1 Switch TrayGetMsg() Case $TRAY_EVENT_MOUSEOVER If $tray_tmr = False Then $tray_pos = MouseGetPos() $tray_tmr = True $tmr_notification = TimerInit() EndIf Case $idExit ; Exit the loop. ExitLoop EndSwitch If $tray_tmr = True Then If TimerDiff($tmr_notification) > 1000 And $notification = False Then ConsoleWrite("--> Notification" & @CRLF) $notification = True EndIf Local $mousetgetpos = MouseGetPos() If Not @error Then If $notification = True Then If $tray_pos[0] < $mousetgetpos[0] -12 Or $tray_pos[0] > $mousetgetpos[0] + 12 Or $tray_pos[1] > $mousetgetpos[1] +20 Or $tray_pos[1] < $mousetgetpos[1] -20 Then $tray_tmr = False ConsoleWrite("<-- Out Notification" & @CRLF) $notification = False Else $tmr_notification = TimerInit() EndIf EndIf EndIf EndIf WEnd Edited April 23, 2017 by nend
genius257 Posted April 21, 2017 Posted April 21, 2017 (edited) Hi @nend. _WinAPI_ShellNotifyIconGetRect You may experience problems with the example, if you use Windows 10. Just save a copy and remove the if code block. Edit: There may be a event that will help you, from the Windows API, but i can't find anything currently. So my suggestion for the icon leave event problem would be setting a low level mouse hook with _WinAPI_SetWindowsHookEx ($WH_MOUSE_LL) on the $TRAY_EVENT_MOUSEOVER event, and removing the hook once the mouse leaves the area specified from _WinAPI_ShellNotifyIconGetRect. Also i would suggest you looking into: AutoItSetOption("GUIOnEventMode", 1), AutoItSetOption("TrayOnEventMode", 1), GUISetOnEvent and TraySetOnEvent Hopefully some of this will help you reaching your solution. Edited April 21, 2017 by genius257 nend 1 To show your appreciation My highlighted topics: AutoIt Package Manager, AutoItObject Pure AutoIt, AutoIt extension for Visual Studio Code Github: AutoIt HTTP Server, AutoIt HTML Parser
nend Posted April 22, 2017 Author Posted April 22, 2017 (edited) @genius257 Thanks for your reply It sure looks good, but I'm having some few issues. - how to get the the handle from the parent window of my own tray menu icon which I use in this program so that I can use _WinAPI_ShellNotifyIconGetRect ? - If I use #include <Array.au3> in the script this example doesn't work anymore, mabey it has something to do with "WinGetHandle(AutoItWinGetTitle())" I hoop you can help so I'm gonna finnish my script. EDIT: I think I found the problem, I had to put a sleep(200) after making the tray menu. I think it had to do with that the icon isn't yet build before _WinAPI_ShellNotifyIconGetRect. Edited April 22, 2017 by nend
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