#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