Burgaud Posted January 7, 2020 Share Posted January 7, 2020 (edited) specifically, I am using the code: tooltip ("sometext"..... ) I would like the script to detect if user clicks on this tooltip (as if it is a clickable button) and performs a task if so. Is this possible? The reason I want to use Tooltip over other methods such as GUICtrlCreateLabel is because I am using tooltip to display a timer constantly and using GUICtrlCreateLabel would unfocus on what the user is doing causing it to lose sound and such. Tooltip does not do that. ADD: I search some threads and found ideas using Mouseclick events and then checking where mouse was clicking at. Is this a good idea? thanks. Edited January 8, 2020 by Burgaud Link to comment Share on other sites More sharing options...
BugFix Posted January 18, 2020 Share Posted January 18, 2020 (edited) You can do it so: expandcollapse popup#include <WinAPI.au3> #include <WindowsConstants.au3> HotKeySet('^+q', '_Exit') ; Ctrl+Shift+Q OnAutoItExitRegister('OnAutoItExit') Global Const $HC_ACTION = 0 Global $hStub_MouseProc = DllCallbackRegister("_MouseProc", "long", "int;wparam;lparam") Global $hmod = _WinAPI_GetModuleHandle(0) Global $hHook = _WinAPI_SetWindowsHookEx($WH_MOUSE_LL, DllCallbackGetPtr($hStub_MouseProc), $hmod) ToolTip(StringFormat("%02d:%02d:%02d", @HOUR, @MIN, @SEC) , 100, 100, 'TOOLTIP - TIME', 1, 1) Global $tTip = _GetRectTip() Global $bClick = False AdlibRegister("_ToolTipRefresh", 1000) While True If $bClick Then $bClick = False ConsoleWrite('Tip was clicked' & @CRLF) EndIf Sleep(100) WEnd Func _Exit() Exit EndFunc Func OnAutoItExit() _WinAPI_UnhookWindowsHookEx($hHook) DllCallbackFree($hStub_MouseProc) EndFunc Func _ToolTipRefresh() ToolTip(StringFormat("%02d:%02d:%02d", @HOUR, @MIN, @SEC) , 100, 100, 'TOOLTIP - TIME', 1, 1) EndFunc Func _GetRectTip() Local $hTip = WinGetHandle('[CLASS:tooltips_class32]') Local $aPos = WinGetPos($hTip) Local $tRECT = DllStructCreate("int Left;int Top;int Right;int Bottom") DllCall("user32", 'long', 'SetRect', 'ptr', DllStructGetPtr($tRECT), 'long', $aPos[0], 'long', $aPos[1], 'long', $aPos[0]+$aPos[2], 'long', $aPos[1]+$aPos[3]) Return $tRECT EndFunc Func _MouseProc($nCode, $wParam, $lParam) Local $info = DllStructCreate("int X;int Y;dword mouseData;dword flags;dword time;ulong_ptr dwExtraInfo", $lParam) If $nCode < 0 Then Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam) If $nCode = $HC_ACTION Then Switch $wParam Case $WM_LBUTTONDOWN If _WinAPI_CoordInRect($tTIP, $info.X, $info.Y) Then $bClick = True EndSwitch EndIf Return _WinAPI_CallNextHookEx($hHook, $nCode, $wParam, $lParam) EndFunc Func _WinAPI_CoordInRect(ByRef $tRECT, $X, $Y) If Not IsDllStruct($tRECT) Then Return SetError(1,0,0) Local $ret = DllCall("user32", "long", "PtInRect", "ptr", DllStructGetPtr($tRECT), "long", $X, "long", $Y) If @error > 0 Then Return SetError(2,@error,0) If $ret[0] Then Return True Else Return False EndIf EndFunc Edited January 19, 2020 by BugFix Musashi and Burgaud 2 Best Regards BugFix 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