Что нового

Определить иконку скрипта в трее, под курсором

Webarion

Осваивающий
Сообщения
143
Репутация
24
Допустим, создана иконка в трее:

Код:
TraySetIcon("shell32.dll", -111)


Как определить, что курсор мыши находится именно под этой иконкой?
 

joiner

Модератор
Локальный модератор
Сообщения
3,556
Репутация
628
если ты сам создаешь иконку, то сам и определяешь клик по ней. для этого в AutoIt есть свои функции.
чего, конкретно, хочешь добиться? ТО неполное
 
Автор
W

Webarion

Осваивающий
Сообщения
143
Репутация
24
Мне не нужен клик, мне нужно определить наведение на иконку.


Добавлено:
Сообщение автоматически объединено:

В общем собрал то, что нужно, но есть резонный вопрос, может есть способ сделать код короче, без подключения UDF?

Код:
#include <GuiToolBar.au3>
#include <_SysTray.au3>

Opt("TrayMenuMode", 3)

$hToolbar = ControlGetHandle('[CLASS:Shell_TrayWnd]', '', 'ToolbarWindow321')
Global $aToolbar = _GUICtrlToolbar_GetButtonSize($hToolbar)

TraySetIcon("shell32.dll", -131)

$exit = TrayCreateItem('Выход')

TraySetState()

While 1
	$nMsg = TrayGetMsg()
	Switch $nMsg
		Case $exit
			Exit
	EndSwitch

	ToolTip(_isMouseIconTray())

	Sleep(100)
WEnd

Func _isMouseIconTray()
	Local $iIndex, $aI, $aM
	$iIndex = _SysTrayIconIndex(@AutoItPID, 2)
	If $iIndex = -1 Then Return SetError(1)
	$aI = _SysTrayIconPos($iIndex)
	If $aI = -1 Then Return SetError(1)
	ReDim $aI[4]
	$aI[2] = $aToolbar[1]
	$aI[3] = $aToolbar[0]
	$aM = __MouseGetPos()
	If $aM[0] >= $aI[0] And $aM[0] <= $aI[0] + $aI[2] And $aM[1] >= $aI[1] And $aM[1] <= $aI[1] + $aI[3] Then Return 1
	Return 0
EndFunc   ;==>_isMouseIconTray

Func __MouseGetPos()
	Local $aPos[2]
	$t_Point = DllStructCreate('struct;long X;long Y;endstruct')
	$aRet = DllCall('user32.dll', 'bool', 'GetCursorPos', 'ptr', DllStructGetPtr($t_Point))
	If (@error) Or (Not $aRet[0]) Then Return SetError(1, 0, 0)
	$aPos[0] = DllStructGetData($t_Point, 'X')
	$aPos[1] = DllStructGetData($t_Point, 'Y')
	Return $aPos
EndFunc   ;==>__MouseGetPos
 

joiner

Модератор
Локальный модератор
Сообщения
3,556
Репутация
628
Код:
#include <windowsconstants.au3>
#include <WinAPI.au3>
#include <Memory.au3>


Global Const $WM_TRAYNOTIFY = $WM_USER + 1
Global Const $NIN_BALLOONSHOW = $WM_USER + 2
Global Const $NIN_BALLOONHIDE = $WM_USER + 3
Global Const $NIN_BALLOONUSERCLICK = $WM_USER + 5
Global Const $NIN_BALLOONTIMEOUT = $WM_USER + 4
Global Const $__gpTrayNotifySubclassProc = __TrayNotify_CreateSubclassProc()

Opt('TrayAutoPause', 0)
Opt('WinTitleMatchMode', 3)
Opt('WinWaitDelay', 0)
Opt('TrayMenuMode', 3)

Global $iTip = 2
Global $hForm = GUICreate('')
DllOpen("comctrl32.dll")

_TrayNotify_Redirect($hForm)
GUIRegisterMsg($WM_TRAYNOTIFY, 'WM_TRAYNOTIFY')

Global $iShow = TrayCreateItem("Show New Tip")
TrayCreateItem("")
Global $iExit = TrayCreateItem("Exit")

TrayTip('Tip', 'This is a tray tip, click here.', 10, 1)

While 1
	Switch TrayGetMsg()
		Case $iShow
			TrayTip('Tip', 'This is a tray tip, click here. [ ' & $iTip & ' ]', 10, 1)
			$iTip += 1
		Case $iExit
			ExitLoop
	EndSwitch
WEnd
_TrayNotify_RemoveRedirect($hForm)

Func WM_TRAYNOTIFY($hWnd, $iMsg, $wParam, $lParam)
	Switch $hWnd
		Case $hForm
			Switch $lParam
				Case 0x00000200
					ConsoleWrite('Наведено на иконку' & @CR)
				Case $NIN_BALLOONSHOW
					ConsoleWrite('Balloon tip show.' & @CR)
				Case $NIN_BALLOONHIDE
					ConsoleWrite('Balloon tip hide.' & @CR)
				Case $NIN_BALLOONUSERCLICK
					ConsoleWrite('Balloon tip click.' & @CR)
				Case $NIN_BALLOONTIMEOUT
					ConsoleWrite('Balloon tip close.' & @CR)
			EndSwitch
	EndSwitch
EndFunc   ;==>WM_TRAYNOTIFY

Func __TrayNotify_CreateSubclassProc()
	Local $aCall = DllCall("kernel32.dll", "ptr", "GetProcAddress", "handle", _WinAPI_GetModuleHandle("user32.dll"), "str", "PostMessageW")
	Local $pPostMessageW = $aCall[0]
	$aCall = DllCall("kernel32.dll", "ptr", "GetProcAddress", "handle", _WinAPI_GetModuleHandle("Comctl32.dll"), "str", "DefSubclassProc")
	Local $pDefSubclassProc = $aCall[0]
	If @AutoItX64 Then; x64
		Local $b = Binary("0x554889e54883ec204881fa01040000753448894d10488955184c8945204c894d28488b4d3848b8") & Binary($pPostMessageW) & Binary("0xffd0674c8b4d28674c8b452067488b551867488b4d1048b8") & Binary($pDefSubclassProc) & Binary("0xffd04883c4205dc3")
	Else; x86
		Local $b = Binary("0x5589e5817d0c010400007513ff7514ff7510ff750cff751cb8") & Binary($pPostMessageW) & Binary("0xffd0ff7514ff7510ff750cff7508b8") & Binary($pDefSubclassProc) & Binary("0xffd05dc21800")
	EndIf
	Local $pMem = _MemVirtualAlloc(0, BinaryLen($b), $MEM_COMMIT, $PAGE_EXECUTE_READWRITE)
	Local $t = DllStructCreate("byte[" & BinaryLen($b) & "]", $pMem)
	DllStructSetData($t, 1, $b)
	Return $pMem
EndFunc   ;==>__TrayNotify_CreateSubclassProc

Func _TrayNotify_Redirect($hWndRedirect)
	DllCall("comctl32.dll", "bool", "SetWindowSubclass", "hwnd", __TrayNotify_AutoItWinGetHandle(), "ptr", $__gpTrayNotifySubclassProc, "uint_ptr", $hWndRedirect, "dword_ptr", $hWndRedirect)
EndFunc   ;==>_TrayNotify_Redirect
Func _TrayNotify_RemoveRedirect($hWndRedirect)
	DllCall("comctl32.dll", "bool", "RemoveWindowSubclass", "hwnd", __TrayNotify_AutoItWinGetHandle(), "ptr", $__gpTrayNotifySubclassProc, "uint_ptr", $hWndRedirect)
EndFunc   ;==>_TrayNotify_RemoveRedirect

Func __TrayNotify_AutoItWinGetHandle()
	Local Static $h
	If IsHWnd($h) Then Return $h
	Local $t = AutoItWinGetTitle()
	AutoItWinSetTitle("096c7d2e-4d24-4103-9503-66748fa96cc7#" & @AutoItPID)
	$h = WinGetHandle("096c7d2e-4d24-4103-9503-66748fa96cc7#" & @AutoItPID)
	AutoItWinSetTitle($t)
	Return $h
EndFunc   ;==>__TrayNotify_AutoItWinGetHandle

взято отсюда
как вариант, еще здесь
 
Автор
W

Webarion

Осваивающий
Сообщения
143
Репутация
24
Спасибо! С машинным кодом интересно :smile:
 
Верх