I'm loving this thread, good work y'all!

---Global MemoryEx plugin needed WM_USER = 0x0400; LR_LOADFROMFILE = 0x0010; LR_SHARED = 0x00008000; LR_DEFAULTSIZE = 0x00000040; IMAGE_ICON = 1; DI_NORMAL = 0x0003; NIF_MESSAGE = 0x00000001; NIF_ICON = 0x00000002; NIF_TIP = 0x00000004; NIF_STATE = 0x00000008; NIF_INFO = 0x00000010; NIF_GUID = 0x00000020; NIF_REALTIME = 0x00000040; NIF_SHOWTIP = 0x00000080; NOTIFYICONDATA_V1_SIZE = 88; NOTIFYICONDATA_V2_SIZE = 488; NOTIFYICONDATA_V3_SIZE = 504; NOTIFYICONDATA_V4_SIZE = 508; NIIF_NONE = 0x00000000; NIIF_INFO = 0x00000001; NIIF_WARNING = 0x00000002; NIIF_ERROR = 0x00000003; NIIF_USER = 0x00000004; NIIF_NOSOUND = 0x00000010; NIIF_LARGE_ICON = 0x00000020; NIIF_RESPECT_QUIET_TIME = 0x00000080; NIIF_ICON_MASK = 0x0000000F; NIS_HIDDEN = 0x00000001; NIS_SHAREDICON = 0x00000002; NOTIFYICON_VERSION = 3; NOTIFYICON_VERSION_4 = 4; NIM_ADD = 0x00000000; NIM_DELETE = 0x00000002; NIM_MODIFY = 0x00000001; HWND_MESSAGE = -3; WM_LBUTTONDOWN = 0x0201; WM_LBUTTONUP = 0x0202; WM_RBUTTONDOWN = 0x0204; WM_RBUTTONUP = 0x0205; WM_CONTEXTMENU = 0x007B; TC_CBACK = WM_USER + 222; Shell32Library = Library.Load("Shell32.dll"); User32Library = Library.Load("user32.dll"); PTR = INT; LONG = INT; HWND = INT; HICON = INT; TCHAR = STRING; GUID = INT; NOTIFYICONDATA = MemoryEx.DefineStruct{ DWORD "cbSize"; HWND "hWnd"; UINT "uID"; UINT "uFlags"; UINT "uCallbackMessage"; HICON "hIcon"; TCHAR ("szTip",128,1,MEMEX_ASCII); DWORD "dwState"; DWORD "dwStateMask"; TCHAR ("szInfo",256,1,MEMEX_ASCII); UNION { UINT "uTimeout"; UINT "uVersion"; }; TCHAR ("szInfoTitle",256,1,MEMEX_ASCII); DWORD "dwInfoFlags"; GUID "guidItem"; HICON "hBalloonIcon"; }; Tray = {} Tray.FreeIcon = function(sIcon) local hIcon = User32Library.DestroyIcon(sIcon) if hIcon ~= 0 then return true, "OK" else return false, "Can't destroy icon" end end; Tray.LoadIcon = function(sIcon) local hIcon = User32Library.LoadImageA(0,sIcon,IMAGE_ICON,0,0,LR_LOADFROMFILE) if (hIcon ~= nil and hIcon > 0) then return true, hIcon else return false, "Can't load icon" end end; Tray.DllVersionInfo = function() local OS = System.GetOSName(); if OS == "" then return false, "Can't determine OS" end if OS == "Windows XP" or OS == "Windows Server 2003" then Tray.MainStructSize = NOTIFYICON_VERSION end Tray.OSName = OS Tray.VersionSet = 1 return true, "OK" end; Tray.CreateTrayIcon = function(iID,sIcon,sTool) if Tray.VersionSet ~= 1 then local x,y = Tray.DllVersionInfo() if not x then return false, y end end local x,Ih = Tray.LoadIcon(sIcon) if not x then return false, Ih end local lpBuff = MemoryEx.Allocate(MemoryEx.StructSize(NOTIFYICONDATA) + 100); if(lpBuff)then hStruct = MemoryEx.AssignStruct(lpBuff + 50,NOTIFYICONDATA); if(hStruct)then hStruct.hWnd = Application.GetWndHandle(); hStruct.uID = iID; hStruct.uFlags = NIF_MESSAGE + NIF_ICON + NIF_TIP; hStruct.uCallbackMessage = TC_CBACK; hStruct.hIcon = Ih; hStruct.szTip = sTool; hStruct.dwState = NIS_HIDDEN; hStruct.dwStateMask = NIS_HIDDEN; hStruct.szInfo = ""; hStruct.uTimeout = 0; hStruct.uVersion = NOTIFYICON_VERSION; hStruct.szInfoTitle = ""; hStruct.dwInfoFlags = NIIF_NONE; hStruct.guidItem = 0; hStruct.hBalloonIcon = ""; hStruct.cbSize = Tray.MainStructSize or hStruct:Size(); else MemoryEx.Free(lpBuff); return false, "Can't open structure" end else return false, "Can't create buffer" end local poi = hStruct:GetPointer(); if tonumber(Shell32Library.Shell_NotifyIcon(NIM_ADD,poi)) == 0 then MemoryEx.Free(lpBuff); hStruct:Close(); Tray.FreeIcon(Ih); return false, "Create tray icon failed" else MemoryEx.Free(lpBuff); hStruct:Close(); Tray.FreeIcon(Ih); return true, "OK" end end; Tray.SetToolTip = function(iID,tip) local lpBuff = MemoryEx.Allocate(MemoryEx.StructSize(NOTIFYICONDATA) + 100); if(lpBuff)then hStruct = MemoryEx.AssignStruct(lpBuff + 50,NOTIFYICONDATA); if(hStruct)then hStruct.hWnd = Application.GetWndHandle(); hStruct.uID = iID; hStruct.uFlags = NIF_TIP; hStruct.uCallbackMessage = TC_CBACK; hStruct.hIcon = Ih; hStruct.szTip = tip; hStruct.dwState = NIS_HIDDEN; hStruct.dwStateMask = NIS_HIDDEN; hStruct.szInfo = ""; hStruct.uTimeout = 0; hStruct.uVersion = NOTIFYICON_VERSION; hStruct.szInfoTitle = ""; hStruct.dwInfoFlags = NIIF_NONE; hStruct.guidItem = 0; hStruct.hBalloonIcon = ""; hStruct.cbSize = Tray.MainStructSize or hStruct:Size(); else MemoryEx.Free(lpBuff); return false, "Can't open structure" end else return false, "Can't create buffer" end local poi = hStruct:GetPointer(); if tonumber(Shell32Library.Shell_NotifyIcon(NIM_MODIFY,poi)) == 0 then MemoryEx.Free(lpBuff); hStruct:Close(); return false, "Set tool tip failed" else MemoryEx.Free(lpBuff); hStruct:Close(); return true, "OK" end end; Tray.ShowBalloon = function(iID,nTimeout,sTitle,sMessage,bNosound,bLargeIcon,Icon,bQuiet) local lpBuff = MemoryEx.Allocate(MemoryEx.StructSize(NOTIFYICONDATA) + 100); if(lpBuff)then hStruct = MemoryEx.AssignStruct(lpBuff + 50,NOTIFYICONDATA); if(hStruct)then hStruct.hWnd = Application.GetWndHandle(); hStruct.uID = iID; hStruct.uFlags = NIF_MESSAGE + NIF_INFO; hStruct.uCallbackMessage = TC_CBACK; hStruct.hIcon = Ih; hStruct.szTip = sTool; hStruct.dwState = NIS_HIDDEN; hStruct.dwStateMask = NIS_HIDDEN; hStruct.szInfo = sMessage; hStruct.uTimeout = nTimeout; hStruct.uVersion = NOTIFYICON_VERSION; hStruct.szInfoTitle = sTitle; local Iflags = Icon; if bNosound then if Tray.OSName ~= "Windows 2000" then Iflags = Iflags + NIIF_NOSOUND; end end if bLargeIcon then if Tray.OSName == "Windows 8" or Tray.OSName == "Windows Server 2012" or Tray.OSName == "Windows 7" or Tray.OSName == "Windows Server 2008 R2" or Tray.OSName == "Windows Vista" or Tray.OSName == "Windows Server 2008" then Iflags = Iflags + NIIF_LARGE_ICON; end end if bQuiet then if Tray.OSName == "Windows 8" or Tray.OSName == "Windows Server 2012" or Tray.OSName == "Windows 7" then Iflags = Iflags + NIIF_RESPECT_QUIET_TIME; end end hStruct.dwInfoFlags = Iflags; hStruct.guidItem = 0; hStruct.hBalloonIcon = ""; hStruct.cbSize = Tray.MainStructSize or hStruct:Size(); else MemoryEx.Free(lpBuff); return false, "Can't open structure" end else return false, "Can't create buffer" end local poi = hStruct:GetPointer(); if tonumber(Shell32Library.Shell_NotifyIcon(NIM_MODIFY,poi)) == 0 then MemoryEx.Free(lpBuff); hStruct:Close(); return false, "Set balloon failed" else MemoryEx.Free(lpBuff); hStruct:Close(); return true, "OK" end end; Tray.DeleteTrayIcon = function(iID) local lpBuff = MemoryEx.Allocate(MemoryEx.StructSize(NOTIFYICONDATA) + 100); if(lpBuff)then hStruct = MemoryEx.AssignStruct(lpBuff + 50,NOTIFYICONDATA); if(hStruct)then hStruct.hWnd = Application.GetWndHandle(); hStruct.uID = iID; hStruct.uFlags = NIF_MESSAGE + NIF_ICON; hStruct.uCallbackMessage = TC_CBACK; hStruct.hIcon = Ih; hStruct.szTip = ""; hStruct.dwState = NIS_HIDDEN; hStruct.dwStateMask = NIS_HIDDEN; hStruct.szInfo = ""; hStruct.uTimeout = 0; hStruct.uVersion = NOTIFYICON_VERSION; hStruct.szInfoTitle = ""; hStruct.dwInfoFlags = NIIF_NONE; hStruct.guidItem = 0; hStruct.hBalloonIcon = ""; hStruct.cbSize = Tray.MainStructSize or hStruct:Size(); else MemoryEx.Free(lpBuff); return false, "Can't open structure" end else return false, "Can't create buffer" end local poi = hStruct:GetPointer(); if tonumber(Shell32Library.Shell_NotifyIcon(NIM_DELETE,poi)) == 0 then MemoryEx.Free(lpBuff); hStruct:Close(); return false, "Delete tray icon failed" else MemoryEx.Free(lpBuff); hStruct:Close(); return true, "OK" end end; Tray.ChangeIcon = function(iID,sIcon) local x,Ih = Tray.LoadIcon(sIcon) if not x then return false, Ih end local lpBuff = MemoryEx.Allocate(MemoryEx.StructSize(NOTIFYICONDATA) + 100); if(lpBuff)then hStruct = MemoryEx.AssignStruct(lpBuff + 50,NOTIFYICONDATA); if(hStruct)then hStruct.hWnd = Application.GetWndHandle(); hStruct.uID = iID; hStruct.uFlags = NIF_MESSAGE + NIF_ICON; hStruct.uCallbackMessage = TC_CBACK; hStruct.hIcon = Ih; hStruct.szTip = tip; hStruct.dwState = NIS_HIDDEN; hStruct.dwStateMask = NIS_HIDDEN; hStruct.szInfo = ""; hStruct.uTimeout = 0; hStruct.uVersion = NOTIFYICON_VERSION; hStruct.szInfoTitle = ""; hStruct.dwInfoFlags = NIIF_NONE; hStruct.guidItem = 0; hStruct.hBalloonIcon = ""; hStruct.cbSize = Tray.MainStructSize or hStruct:Size(); else MemoryEx.Free(lpBuff); return false, "Can't open structure" end else return false, "Can't create buffer" end local poi = hStruct:GetPointer(); if tonumber(Shell32Library.Shell_NotifyIcon(NIM_MODIFY,poi)) == 0 then MemoryEx.Free(lpBuff); hStruct:Close(); Tray.FreeIcon(Ih); return false, "Change icon failed" else MemoryEx.Free(lpBuff); hStruct:Close(); Tray.FreeIcon(Ih); return true, "OK" end end; Tray.Callback = function (hwnd,umsg,wParam,lParam) if lParam == WM_LBUTTONDOWN then Debug.Print("WM_LBUTTONDOWN("..wParam..")\r\n"); elseif lParam == WM_LBUTTONUP then Debug.Print("WM_LBUTTONUP("..wParam..")\r\n"); elseif lParam == WM_RBUTTONDOWN then Debug.Print("WM_RBUTTONDOWN("..wParam..")\r\n"); elseif lParam == WM_RBUTTONUP then Debug.Print("WM_RBUTTONUP("..wParam..")\r\n"); end end; -- On Show --Debug.ShowWindow(); local s = Subclass.Create(Application.GetWndHandle(), function(hWnd,uMsg,wParam,lParam) if(uMsg == TC_CBACK)then Tray.Callback(hwnd,umsg,wParam,lParam) return 0; end return Subclass.OldWinProc(hWnd,uMsg,wParam,lParam); end) local x,err = Tray.CreateTrayIcon(101,_SourceFolder.."\\Autoplay\\Icons\\1.ico","Notification Icon 1") if not x then Dialog.Message("",err) end --On Close Tray.DeleteTrayIcon(101) Subclass.Remove(Application.GetWndHandle()) --[[ Show Ballon Example -- Tray ID -- Timeout, works with Win 200/XP only otherwise ignored -- Title, max 48 character max -- Message, 200 character max -- No sound, Ignored on win 2000 -- Large icon, ignored on win 2000/XP -- Stock Icon = NIIF_NONE NIIF_INFO NIIF_WARNING NIIF_ERROR -- Respect quiet time, Win 7/8 ignored otherwise local x, y = Tray.ShowBalloon(101,0,"","Test Message\r\nMulti Line",false,false,NIIF_WARNING,false) if not x then Dialog.Message("",y) end --]]
WM_CLOSE = 0x0010; function MyCallback(hWnd, uMsg, wParam, lParam) -- must be called before "Subclass.Remove" Subclass.OldWinProc(hWnd, uMsg, wParam, lParam); -- if the window closes if (uMsg == WM_CLOSE) then -- The subclass will now be removed! Subclass.Remove(hWnd); end end Subclass.Create(Application.GetWndHandle(), MyCallback);
---Global MemoryEx plugin needed TrayCallBack = {} function TrayCallBack.OnLeftButton(nTrayID,bState,xPos,yPos) if bState then local t ={} t[1] = {}; t[1].Text = "Left Button ID: "..nTrayID; Application.ShowPopupMenu(xPos,yPos,t,8,32,true,false) else --Button down click end end function TrayCallBack.OnRightButton(nTrayID,bState,xPos,yPos) if bState then local t ={} t[1] = {}; t[1].Text = "Right Button ID: "..nTrayID; Application.ShowPopupMenu(xPos,yPos,t,8,32,true,false) else --Button down click end end function TrayCallBack.OnBalloon() end -- Everything past here is modue based WM_USER = 0x0400; LR_LOADFROMFILE = 0x0010; LR_SHARED = 0x00008000; LR_DEFAULTSIZE = 0x00000040; IMAGE_ICON = 1; DI_NORMAL = 0x0003; NIF_MESSAGE = 0x00000001; NIF_ICON = 0x00000002; NIF_TIP = 0x00000004; NIF_STATE = 0x00000008; NIF_INFO = 0x00000010; NIF_GUID = 0x00000020; NIF_REALTIME = 0x00000040; NIF_SHOWTIP = 0x00000080; NOTIFYICONDATA_V1_SIZE = 88; NOTIFYICONDATA_V2_SIZE = 488; NOTIFYICONDATA_V3_SIZE = 504; NOTIFYICONDATA_V4_SIZE = 508; NIIF_NONE = 0x00000000; NIIF_INFO = 0x00000001; NIIF_WARNING = 0x00000002; NIIF_ERROR = 0x00000003; NIIF_USER = 0x00000004; NIIF_NOSOUND = 0x00000010; NIIF_LARGE_ICON = 0x00000020; NIIF_RESPECT_QUIET_TIME = 0x00000080; NIIF_ICON_MASK = 0x0000000F; NIS_HIDDEN = 0x00000001; NIS_SHAREDICON = 0x00000002; NOTIFYICON_VERSION = 3; NOTIFYICON_VERSION_4 = 4; NIM_ADD = 0x00000000; NIM_DELETE = 0x00000002; NIM_MODIFY = 0x00000001; HWND_MESSAGE = -3; WM_LBUTTONDOWN = 0x0201; WM_LBUTTONUP = 0x0202; WM_RBUTTONDOWN = 0x0204; WM_RBUTTONUP = 0x0205; WM_CONTEXTMENU = 0x007B; TC_CBACK = WM_USER + 222; NIM_SETVERSION =0x00000004; NIM_SETFOCUS = 0x00000003; Shell32Library = Library.Load("Shell32.dll"); User32Library = Library.Load("user32.dll"); PTR = INT; LONG = INT; HWND = INT; HICON = INT; TCHAR = STRING; GUID = INT; NOTIFYICONDATA = MemoryEx.DefineStruct{ DWORD "cbSize"; HWND "hWnd"; UINT "uID"; UINT "uFlags"; UINT "uCallbackMessage"; HICON "hIcon"; TCHAR ("szTip",128,1,MEMEX_ASCII); DWORD "dwState"; DWORD "dwStateMask"; TCHAR ("szInfo",256,1,MEMEX_ASCII); UNION { UINT "uTimeout"; UINT "uVersion"; }; TCHAR ("szInfoTitle",256,1,MEMEX_ASCII); DWORD "dwInfoFlags"; GUID "guidItem"; HICON "hBalloonIcon"; }; TrayInternal = {} TrayInternal.CreateHost = function() local I = User32Library.CreateWindowExA(0,"Edit","",1342308359,1,1,0,0,Application.GetWndHandle(),0,0,0) if I and (type(I) ~= "number") then return false, "Can't create callback" else local s = Subclass.Create(I, function(hWnd,uMsg,wParam,lParam) if(uMsg == TC_CBACK)then local M = System.GetMousePosition(false,nil) if lParam == WM_LBUTTONDOWN then TrayCallBack.OnLeftButton(wParam,false,M.X,M.Y) TrayInternal.SetFocus(wParam) elseif lParam == WM_LBUTTONUP then TrayCallBack.OnLeftButton(wParam,true,M.X,M.Y) TrayInternal.SetFocus(wParam) elseif lParam == WM_RBUTTONDOWN then TrayCallBack.OnRightButton(wParam,false,M.X,M.Y) TrayInternal.SetFocus(wParam) elseif lParam == WM_RBUTTONUP then TrayCallBack.OnRightButton(wParam,true,M.X,M.Y) TrayInternal.SetFocus(wParam) end end return Subclass.OldWinProc(hWnd,uMsg,wParam,lParam); end) TrayInternal.HostHandle = I return true, I end end; TrayInternal.SetFocus = function(iID) local lpBuff = MemoryEx.Allocate(MemoryEx.StructSize(NOTIFYICONDATA) + 100); if(lpBuff)then hStruct = MemoryEx.AssignStruct(lpBuff + 50,NOTIFYICONDATA); if(hStruct)then hStruct.hWnd = TrayInternal.HostHandle; hStruct.uID = iID; hStruct.uFlags = NIF_MESSAGE; hStruct.uCallbackMessage = TC_CBACK; hStruct.hIcon = Ih; hStruct.szTip = ""; hStruct.dwState = NIS_HIDDEN; hStruct.dwStateMask = NIS_HIDDEN; hStruct.szInfo = ""; hStruct.uTimeout = 0; hStruct.uVersion = NOTIFYICON_VERSION; hStruct.szInfoTitle = ""; hStruct.dwInfoFlags = NIIF_NONE; hStruct.guidItem = 0; hStruct.hBalloonIcon = ""; hStruct.cbSize = Tray.MainStructSize or hStruct:Size(); else MemoryEx.Free(lpBuff) end else return false end local poi = hStruct:GetPointer(); if tonumber(Shell32Library.Shell_NotifyIcon(NIM_SETFOCUS,poi)) == 0 then MemoryEx.Free(lpBuff); hStruct:Close(); return false else MemoryEx.Free(lpBuff); hStruct:Close(); return true end end; TrayInternal.FreeIcon = function(sIcon) local hIcon = User32Library.DestroyIcon(sIcon) if hIcon ~= 0 then return true, "OK" else return false, "Can't destroy icon" end end; TrayInternal.LoadIcon = function(sIcon) local hIcon = User32Library.LoadImageA(0,sIcon,IMAGE_ICON,0,0,LR_LOADFROMFILE) if (hIcon ~= nil and hIcon > 0) then return true, hIcon else return false, "Can't load icon" end end; TrayInternal.DllVersionInfo = function() local OS = System.GetOSName(); if OS == "" then return false, "Can't determine OS" end if OS == "Windows XP" or OS == "Windows Server 2003" then Tray.MainStructSize = NOTIFYICON_VERSION end TrayInternal.OSName = OS TrayInternal.VersionSet = 1 return true, "OK" end; Tray = {} Tray.CreateTrayIcon = function(iID,sIcon,sTool) if TrayInternal.HostHandle ~= 1 then local x,y = TrayInternal.CreateHost() if not x then return false, y end end if TrayInternal.VersionSet ~= 1 then local x,y = TrayInternal.DllVersionInfo() if not x then return false, y end end local x,Ih = TrayInternal.LoadIcon(sIcon) if not x then return false, Ih end local lpBuff = MemoryEx.Allocate(MemoryEx.StructSize(NOTIFYICONDATA) + 100); if(lpBuff)then hStruct = MemoryEx.AssignStruct(lpBuff + 50,NOTIFYICONDATA); if(hStruct)then hStruct.hWnd = TrayInternal.HostHandle; hStruct.uID = iID; hStruct.uFlags = NIF_MESSAGE + NIF_ICON + NIF_TIP; hStruct.uCallbackMessage = TC_CBACK; hStruct.hIcon = Ih; hStruct.szTip = sTool; hStruct.dwState = NIS_HIDDEN; hStruct.dwStateMask = NIS_HIDDEN; hStruct.szInfo = ""; hStruct.uTimeout = 0; hStruct.uVersion = NOTIFYICON_VERSION; hStruct.szInfoTitle = ""; hStruct.dwInfoFlags = NIIF_NONE; hStruct.guidItem = 0; hStruct.hBalloonIcon = ""; hStruct.cbSize = Tray.MainStructSize or hStruct:Size(); else MemoryEx.Free(lpBuff); return false, "Can't open structure" end else return false, "Can't create buffer" end local poi = hStruct:GetPointer(); if tonumber(Shell32Library.Shell_NotifyIcon(NIM_ADD,poi)) == 0 then MemoryEx.Free(lpBuff); hStruct:Close(); TrayInternal.FreeIcon(Ih); return false, "Create tray icon failed" else Shell32Library.Shell_NotifyIcon(NIM_SETVERSION,poi) MemoryEx.Free(lpBuff); hStruct:Close(); TrayInternal.FreeIcon(Ih); return true, "OK" end end; Tray.SetToolTip = function(iID,tip) local lpBuff = MemoryEx.Allocate(MemoryEx.StructSize(NOTIFYICONDATA) + 100); if(lpBuff)then hStruct = MemoryEx.AssignStruct(lpBuff + 50,NOTIFYICONDATA); if(hStruct)then hStruct.hWnd = TrayInternal.HostHandle; hStruct.uID = iID; hStruct.uFlags = NIF_TIP; hStruct.uCallbackMessage = TC_CBACK; hStruct.hIcon = Ih; hStruct.szTip = tip; hStruct.dwState = NIS_HIDDEN; hStruct.dwStateMask = NIS_HIDDEN; hStruct.szInfo = ""; hStruct.uTimeout = 0; hStruct.uVersion = NOTIFYICON_VERSION; hStruct.szInfoTitle = ""; hStruct.dwInfoFlags = NIIF_NONE; hStruct.guidItem = 0; hStruct.hBalloonIcon = ""; hStruct.cbSize = Tray.MainStructSize or hStruct:Size(); else MemoryEx.Free(lpBuff); return false, "Can't open structure" end else return false, "Can't create buffer" end local poi = hStruct:GetPointer(); if tonumber(Shell32Library.Shell_NotifyIcon(NIM_MODIFY,poi)) == 0 then MemoryEx.Free(lpBuff); hStruct:Close(); return false, "Set tool tip failed" else MemoryEx.Free(lpBuff); hStruct:Close(); return true, "OK" end end; Tray.ShowBalloon = function(iID,nTimeout,sTitle,sMessage,bNosound,bLargeIcon,Icon,bQuiet) local lpBuff = MemoryEx.Allocate(MemoryEx.StructSize(NOTIFYICONDATA) + 100); if(lpBuff)then hStruct = MemoryEx.AssignStruct(lpBuff + 50,NOTIFYICONDATA); if(hStruct)then hStruct.hWnd = TrayInternal.HostHandle; hStruct.uID = iID; hStruct.uFlags = NIF_MESSAGE + NIF_INFO; hStruct.uCallbackMessage = TC_CBACK; hStruct.hIcon = Ih; hStruct.szTip = sTool; hStruct.dwState = NIS_HIDDEN; hStruct.dwStateMask = NIS_HIDDEN; hStruct.szInfo = sMessage; hStruct.uTimeout = nTimeout; hStruct.uVersion = NOTIFYICON_VERSION; hStruct.szInfoTitle = sTitle; local Iflags = Icon; if bNosound then if TrayInternal.OSName ~= "Windows 2000" then Iflags = Iflags + NIIF_NOSOUND; end end if bLargeIcon then if TrayInternal.OSName == "Windows 8" or TrayInternal.OSName == "Windows Server 2012" or TrayInternal.OSName == "Windows 7" or TrayInternal.OSName == "Windows Server 2008 R2" or TrayInternal.OSName == "Windows Vista" or TrayInternal.OSName == "Windows Server 2008" then Iflags = Iflags + NIIF_LARGE_ICON; end end if bQuiet then if TrayInternal.OSName == "Windows 8" or TrayInternal.OSName == "Windows Server 2012" or TrayInternal.OSName == "Windows 7" then Iflags = Iflags + NIIF_RESPECT_QUIET_TIME; end end hStruct.dwInfoFlags = Iflags; hStruct.guidItem = 0; hStruct.hBalloonIcon = ""; hStruct.cbSize = Tray.MainStructSize or hStruct:Size(); else MemoryEx.Free(lpBuff); return false, "Can't open structure" end else return false, "Can't create buffer" end local poi = hStruct:GetPointer(); if tonumber(Shell32Library.Shell_NotifyIcon(NIM_MODIFY,poi)) == 0 then MemoryEx.Free(lpBuff); hStruct:Close(); return false, "Set balloon failed" else MemoryEx.Free(lpBuff); hStruct:Close(); return true, "OK" end end; Tray.DeleteTrayIcon = function(iID) local lpBuff = MemoryEx.Allocate(MemoryEx.StructSize(NOTIFYICONDATA) + 100); if(lpBuff)then hStruct = MemoryEx.AssignStruct(lpBuff + 50,NOTIFYICONDATA); if(hStruct)then hStruct.hWnd = TrayInternal.HostHandle; hStruct.uID = iID; hStruct.uFlags = NIF_MESSAGE + NIF_ICON; hStruct.uCallbackMessage = TC_CBACK; hStruct.hIcon = Ih; hStruct.szTip = ""; hStruct.dwState = NIS_HIDDEN; hStruct.dwStateMask = NIS_HIDDEN; hStruct.szInfo = ""; hStruct.uTimeout = 0; hStruct.uVersion = NOTIFYICON_VERSION; hStruct.szInfoTitle = ""; hStruct.dwInfoFlags = NIIF_NONE; hStruct.guidItem = 0; hStruct.hBalloonIcon = ""; hStruct.cbSize = Tray.MainStructSize or hStruct:Size(); else MemoryEx.Free(lpBuff); return false, "Can't open structure" end else return false, "Can't create buffer" end local poi = hStruct:GetPointer(); if tonumber(Shell32Library.Shell_NotifyIcon(NIM_DELETE,poi)) == 0 then MemoryEx.Free(lpBuff); hStruct:Close(); return false, "Delete tray icon failed" else MemoryEx.Free(lpBuff); hStruct:Close(); return true, "OK" end end; Tray.ChangeIcon = function(iID,sIcon) local x,Ih = TrayInternal.LoadIcon(sIcon) if not x then return false, Ih end local lpBuff = MemoryEx.Allocate(MemoryEx.StructSize(NOTIFYICONDATA) + 100); if(lpBuff)then hStruct = MemoryEx.AssignStruct(lpBuff + 50,NOTIFYICONDATA); if(hStruct)then hStruct.hWnd = TrayInternal.HostHandle; hStruct.uID = iID; hStruct.uFlags = NIF_MESSAGE + NIF_ICON; hStruct.uCallbackMessage = TC_CBACK; hStruct.hIcon = Ih; hStruct.szTip = tip; hStruct.dwState = NIS_HIDDEN; hStruct.dwStateMask = NIS_HIDDEN; hStruct.szInfo = ""; hStruct.uTimeout = 0; hStruct.uVersion = NOTIFYICON_VERSION; hStruct.szInfoTitle = ""; hStruct.dwInfoFlags = NIIF_NONE; hStruct.guidItem = 0; hStruct.hBalloonIcon = ""; hStruct.cbSize = Tray.MainStructSize or hStruct:Size(); else MemoryEx.Free(lpBuff); return false, "Can't open structure" end else return false, "Can't create buffer" end local poi = hStruct:GetPointer(); if tonumber(Shell32Library.Shell_NotifyIcon(NIM_MODIFY,poi)) == 0 then MemoryEx.Free(lpBuff); hStruct:Close(); TrayInternal.FreeIcon(Ih); return false, "Change icon failed" else MemoryEx.Free(lpBuff); hStruct:Close(); TrayInternal.FreeIcon(Ih); return true, "OK" end end; -- On Show local x,err = Tray.CreateTrayIcon(101,_SourceFolder.."\\Autoplay\\Icons\\1.ico","Notification Icon 1") if not x then Dialog.Message("",err) end --On Close Tray.DeleteTrayIcon(101) --[[ Show Balloon Example -- Tray ID -- Timeout - Works with Win 2000/XP only otherwise ignored -- Title - 48 character max -- Message - 200 character max -- No sound - Ignored on Win 2000 -- Large icon - ignored on Win 2000/XP -- Stock Icon - NIIF_NONE - NIIF_INFO - NIIF_WARNING - NIIF_ERROR -- Respect quiet time - Win 7/8 ignored otherwise local x, y = Tray.ShowBalloon(101,10000,"Test Title","Test Message",false,false,NIIF_WARNING,false) if not x then Dialog.Message("",y) end --]]
---Global MemoryEx plugin needed TrayCallBack = {} function TrayCallBack.OnLeftButton(nTrayID,bState,xPos,yPos) if bState then local t ={} t[1] = {}; t[1].Text = "Left Button ID: "..nTrayID; Application.ShowPopupMenu(xPos,yPos,t,8,32,true,false) else --Button down click end end function TrayCallBack.OnRightButton(nTrayID,bState,xPos,yPos) if bState then local t ={} t[1] = {}; t[1].Text = "Right Button ID: "..nTrayID; Application.ShowPopupMenu(xPos,yPos,t,8,32,true,false) else --Button down click end end function TrayCallBack.OnBalloon() end -- Everything past here is module based LR_LOADFROMFILE = 0x0010; IMAGE_ICON = 1; NIF_MESSAGE = 0x00000001; NIF_ICON = 0x00000002; NIF_TIP = 0x00000004; NIF_INFO = 0x00000010; NIIF_NONE = 0x00000000; NIIF_INFO = 0x00000001; NIIF_WARNING = 0x00000002; NIIF_ERROR = 0x00000003; NIIF_USER = 0x00000004; NIIF_NOSOUND = 0x00000010; NIIF_LARGE_ICON = 0x00000020; NIIF_RESPECT_QUIET_TIME = 0x00000080; NIS_HIDDEN = 0x00000001; NOTIFYICON_VERSION = 3; NIM_ADD = 0x00000000; NIM_DELETE = 0x00000002; NIM_MODIFY = 0x00000001; WM_LBUTTONDOWN = 0x0201; WM_LBUTTONUP = 0x0202; WM_RBUTTONDOWN = 0x0204; WM_RBUTTONUP = 0x0205; TC_CBACK = 0x4DE; NIM_SETVERSION =0x00000004; NIM_SETFOCUS = 0x00000003; WM_DESTROY = 0x0002; Shell32Library = Library.Load("Shell32.dll"); User32Library = Library.Load("user32.dll"); PTR = INT; LONG = INT; HWND = INT; HICON = INT; TCHAR = STRING; GUID = INT; NOTIFYICONDATA = MemoryEx.DefineStruct{ DWORD "cbSize"; HWND "hWnd"; UINT "uID"; UINT "uFlags"; UINT "uCallbackMessage"; HICON "hIcon"; TCHAR ("szTip",128,1,MEMEX_ASCII); DWORD "dwState"; DWORD "dwStateMask"; TCHAR ("szInfo",256,1,MEMEX_ASCII); UNION { UINT "uTimeout"; UINT "uVersion"; }; TCHAR ("szInfoTitle",256,1,MEMEX_ASCII); DWORD "dwInfoFlags"; GUID "guidItem"; HICON "hBalloonIcon"; }; TrayInternal = {} TrayInternal.CreateHost = function() local I = User32Library.CreateWindowExA(0,"Edit","",1342308359,1,1,0,0,Application.GetWndHandle(),0,0,0) if I and (type(I) ~= "number") then return false, "Can't create callback" else local s = Subclass.Create(I, function(hWnd,uMsg,wParam,lParam) if(uMsg == WM_DESTROY)then Subclass.Remove(I); return 0 end if(uMsg == TC_CBACK)then local M = System.GetMousePosition(false,nil) if lParam == WM_LBUTTONDOWN then TrayCallBack.OnLeftButton(wParam,false,M.X,M.Y) TrayInternal.SetFocus(wParam) elseif lParam == WM_LBUTTONUP then TrayCallBack.OnLeftButton(wParam,true,M.X,M.Y) TrayInternal.SetFocus(wParam) elseif lParam == WM_RBUTTONDOWN then TrayCallBack.OnRightButton(wParam,false,M.X,M.Y) TrayInternal.SetFocus(wParam) elseif lParam == WM_RBUTTONUP then TrayCallBack.OnRightButton(wParam,true,M.X,M.Y) TrayInternal.SetFocus(wParam) end return 0 end return Subclass.OldWinProc(hWnd,uMsg,wParam,lParam); end) TrayInternal.HostHandle = I return true, I end end; TrayInternal.SetFocus = function(iID) local lpBuff = MemoryEx.Allocate(MemoryEx.StructSize(NOTIFYICONDATA) + 100); if(lpBuff)then hStruct = MemoryEx.AssignStruct(lpBuff + 50,NOTIFYICONDATA); if(hStruct)then hStruct.hWnd = TrayInternal.HostHandle; hStruct.uID = iID; hStruct.uFlags = NIF_MESSAGE; hStruct.uCallbackMessage = TC_CBACK; hStruct.hIcon = Ih; hStruct.szTip = ""; hStruct.dwState = NIS_HIDDEN; hStruct.dwStateMask = NIS_HIDDEN; hStruct.szInfo = ""; hStruct.uTimeout = 0; hStruct.uVersion = NOTIFYICON_VERSION; hStruct.szInfoTitle = ""; hStruct.dwInfoFlags = NIIF_NONE; hStruct.guidItem = 0; hStruct.hBalloonIcon = ""; hStruct.cbSize = Tray.MainStructSize or hStruct:Size(); else MemoryEx.Free(lpBuff) end else return false end local poi = hStruct:GetPointer(); if tonumber(Shell32Library.Shell_NotifyIcon(NIM_SETFOCUS,poi)) == 0 then MemoryEx.Free(lpBuff); hStruct:Close(); return false else MemoryEx.Free(lpBuff); hStruct:Close(); return true end end; TrayInternal.FreeIcon = function(sIcon) local hIcon = User32Library.DestroyIcon(sIcon) if hIcon ~= 0 then return true, "OK" else return false, "Can't destroy icon" end end; TrayInternal.LoadIcon = function(sIcon) local hIcon = User32Library.LoadImageA(0,sIcon,IMAGE_ICON,0,0,LR_LOADFROMFILE) if (hIcon ~= nil and hIcon > 0) then return true, hIcon else return false, "Can't load icon" end end; TrayInternal.DllVersionInfo = function() local OS = System.GetOSName(); if OS == "" then return false, "Can't determine OS" end if OS == "Windows XP" or OS == "Windows Server 2003" then Tray.MainStructSize = NOTIFYICON_VERSION end TrayInternal.OSName = OS TrayInternal.VersionSet = 1 return true, "OK" end; Tray = {} Tray.CreateTrayIcon = function(iID,sIcon,sTool) if TrayInternal.HostHandle ~= 1 then local x,y = TrayInternal.CreateHost() if not x then return false, y end end if TrayInternal.VersionSet ~= 1 then local x,y = TrayInternal.DllVersionInfo() if not x then return false, y end end local x,Ih = TrayInternal.LoadIcon(sIcon) if not x then return false, Ih end local lpBuff = MemoryEx.Allocate(MemoryEx.StructSize(NOTIFYICONDATA) + 100); if(lpBuff)then hStruct = MemoryEx.AssignStruct(lpBuff + 50,NOTIFYICONDATA); if(hStruct)then hStruct.hWnd = TrayInternal.HostHandle; hStruct.uID = iID; hStruct.uFlags = NIF_MESSAGE + NIF_ICON + NIF_TIP; hStruct.uCallbackMessage = TC_CBACK; hStruct.hIcon = Ih; hStruct.szTip = sTool; hStruct.dwState = NIS_HIDDEN; hStruct.dwStateMask = NIS_HIDDEN; hStruct.szInfo = ""; hStruct.uTimeout = 0; hStruct.uVersion = NOTIFYICON_VERSION; hStruct.szInfoTitle = ""; hStruct.dwInfoFlags = NIIF_NONE; hStruct.guidItem = 0; hStruct.hBalloonIcon = ""; hStruct.cbSize = Tray.MainStructSize or hStruct:Size(); else MemoryEx.Free(lpBuff); return false, "Can't open structure" end else return false, "Can't create buffer" end local poi = hStruct:GetPointer(); if tonumber(Shell32Library.Shell_NotifyIcon(NIM_ADD,poi)) == 0 then MemoryEx.Free(lpBuff); hStruct:Close(); TrayInternal.FreeIcon(Ih); return false, "Create tray icon failed" else Shell32Library.Shell_NotifyIcon(NIM_SETVERSION,poi) MemoryEx.Free(lpBuff); hStruct:Close(); TrayInternal.FreeIcon(Ih); return true, "OK" end end; Tray.SetToolTip = function(iID,tip) local lpBuff = MemoryEx.Allocate(MemoryEx.StructSize(NOTIFYICONDATA) + 100); if(lpBuff)then hStruct = MemoryEx.AssignStruct(lpBuff + 50,NOTIFYICONDATA); if(hStruct)then hStruct.hWnd = TrayInternal.HostHandle; hStruct.uID = iID; hStruct.uFlags = NIF_TIP; hStruct.uCallbackMessage = TC_CBACK; hStruct.hIcon = Ih; hStruct.szTip = tip; hStruct.dwState = NIS_HIDDEN; hStruct.dwStateMask = NIS_HIDDEN; hStruct.szInfo = ""; hStruct.uTimeout = 0; hStruct.uVersion = NOTIFYICON_VERSION; hStruct.szInfoTitle = ""; hStruct.dwInfoFlags = NIIF_NONE; hStruct.guidItem = 0; hStruct.hBalloonIcon = ""; hStruct.cbSize = Tray.MainStructSize or hStruct:Size(); else MemoryEx.Free(lpBuff); return false, "Can't open structure" end else return false, "Can't create buffer" end local poi = hStruct:GetPointer(); if tonumber(Shell32Library.Shell_NotifyIcon(NIM_MODIFY,poi)) == 0 then MemoryEx.Free(lpBuff); hStruct:Close(); return false, "Set tool tip failed" else MemoryEx.Free(lpBuff); hStruct:Close(); return true, "OK" end end; Tray.ShowBalloon = function(iID,nTimeout,sTitle,sMessage,bNosound,bLargeIcon,Icon,bQuiet) local lpBuff = MemoryEx.Allocate(MemoryEx.StructSize(NOTIFYICONDATA) + 100); if(lpBuff)then hStruct = MemoryEx.AssignStruct(lpBuff + 50,NOTIFYICONDATA); if(hStruct)then hStruct.hWnd = TrayInternal.HostHandle; hStruct.uID = iID; hStruct.uFlags = NIF_MESSAGE + NIF_INFO; hStruct.uCallbackMessage = TC_CBACK; hStruct.hIcon = Ih; hStruct.szTip = sTool; hStruct.dwState = NIS_HIDDEN; hStruct.dwStateMask = NIS_HIDDEN; hStruct.szInfo = sMessage; hStruct.uTimeout = nTimeout; hStruct.uVersion = NOTIFYICON_VERSION; hStruct.szInfoTitle = sTitle; local Iflags = Icon; if bNosound then if TrayInternal.OSName ~= "Windows 2000" then Iflags = Iflags + NIIF_NOSOUND; end end if bLargeIcon then if TrayInternal.OSName == "Windows 8" or TrayInternal.OSName == "Windows Server 2012" or TrayInternal.OSName == "Windows 7" or TrayInternal.OSName == "Windows Server 2008 R2" or TrayInternal.OSName == "Windows Vista" or TrayInternal.OSName == "Windows Server 2008" then Iflags = Iflags + NIIF_LARGE_ICON; end end if bQuiet then if TrayInternal.OSName == "Windows 8" or TrayInternal.OSName == "Windows Server 2012" or TrayInternal.OSName == "Windows 7" then Iflags = Iflags + NIIF_RESPECT_QUIET_TIME; end end hStruct.dwInfoFlags = Iflags; hStruct.guidItem = 0; hStruct.hBalloonIcon = ""; hStruct.cbSize = Tray.MainStructSize or hStruct:Size(); else MemoryEx.Free(lpBuff); return false, "Can't open structure" end else return false, "Can't create buffer" end local poi = hStruct:GetPointer(); if tonumber(Shell32Library.Shell_NotifyIcon(NIM_MODIFY,poi)) == 0 then MemoryEx.Free(lpBuff); hStruct:Close(); return false, "Set balloon failed" else MemoryEx.Free(lpBuff); hStruct:Close(); return true, "OK" end end; Tray.DeleteTrayIcon = function(iID) local lpBuff = MemoryEx.Allocate(MemoryEx.StructSize(NOTIFYICONDATA) + 100); if(lpBuff)then hStruct = MemoryEx.AssignStruct(lpBuff + 50,NOTIFYICONDATA); if(hStruct)then hStruct.hWnd = TrayInternal.HostHandle; hStruct.uID = iID; hStruct.uFlags = NIF_MESSAGE + NIF_ICON; hStruct.uCallbackMessage = TC_CBACK; hStruct.hIcon = Ih; hStruct.szTip = ""; hStruct.dwState = NIS_HIDDEN; hStruct.dwStateMask = NIS_HIDDEN; hStruct.szInfo = ""; hStruct.uTimeout = 0; hStruct.uVersion = NOTIFYICON_VERSION; hStruct.szInfoTitle = ""; hStruct.dwInfoFlags = NIIF_NONE; hStruct.guidItem = 0; hStruct.hBalloonIcon = ""; hStruct.cbSize = Tray.MainStructSize or hStruct:Size(); else MemoryEx.Free(lpBuff); return false, "Can't open structure" end else return false, "Can't create buffer" end local poi = hStruct:GetPointer(); if tonumber(Shell32Library.Shell_NotifyIcon(NIM_DELETE,poi)) == 0 then MemoryEx.Free(lpBuff); hStruct:Close(); return false, "Delete tray icon failed" else MemoryEx.Free(lpBuff); hStruct:Close(); return true, "OK" end end; Tray.ChangeIcon = function(iID,sIcon) local x,Ih = TrayInternal.LoadIcon(sIcon) if not x then return false, Ih end local lpBuff = MemoryEx.Allocate(MemoryEx.StructSize(NOTIFYICONDATA) + 100); if(lpBuff)then hStruct = MemoryEx.AssignStruct(lpBuff + 50,NOTIFYICONDATA); if(hStruct)then hStruct.hWnd = TrayInternal.HostHandle; hStruct.uID = iID; hStruct.uFlags = NIF_MESSAGE + NIF_ICON; hStruct.uCallbackMessage = TC_CBACK; hStruct.hIcon = Ih; hStruct.szTip = tip; hStruct.dwState = NIS_HIDDEN; hStruct.dwStateMask = NIS_HIDDEN; hStruct.szInfo = ""; hStruct.uTimeout = 0; hStruct.uVersion = NOTIFYICON_VERSION; hStruct.szInfoTitle = ""; hStruct.dwInfoFlags = NIIF_NONE; hStruct.guidItem = 0; hStruct.hBalloonIcon = ""; hStruct.cbSize = Tray.MainStructSize or hStruct:Size(); else MemoryEx.Free(lpBuff); return false, "Can't open structure" end else return false, "Can't create buffer" end local poi = hStruct:GetPointer(); if tonumber(Shell32Library.Shell_NotifyIcon(NIM_MODIFY,poi)) == 0 then MemoryEx.Free(lpBuff); hStruct:Close(); TrayInternal.FreeIcon(Ih); return false, "Change icon failed" else MemoryEx.Free(lpBuff); hStruct:Close(); TrayInternal.FreeIcon(Ih); return true, "OK" end end; -- On Show local x,err = Tray.CreateTrayIcon(101,_SourceFolder.."\\Autoplay\\Icons\\1.ico","Notification Icon 1") if not x then Dialog.Message("",err) end --On Close Tray.DeleteTrayIcon(101) --[[ Show Balloon Example -- Tray ID -- Timeout - Works with Win 2000/XP only otherwise ignored -- Title - 48 character max -- Message - 200 character max -- No sound - Ignored on Win 2000 -- Large icon - ignored on Win 2000/XP -- Stock Icon - NIIF_NONE - NIIF_INFO - NIIF_WARNING - NIIF_ERROR -- Respect quiet time - Win 7/8 ignored otherwise local x, y = Tray.ShowBalloon(101,10000,"Test Title","Test Message",false,false,NIIF_WARNING,false) if not x then Dialog.Message("",y) end --]]
--Global Shell32 = Library.Load("Shell32.dll"); User32 = Library.Load("user32.dll"); IMAGE_ICON = 1; LR_LOADFROMFILE = 0x0010; NIF_MESSAGE = 0x00000001; NIF_ICON = 0x00000002; NIF_TIP = 0x00000004; NIF_INFO = 0x00000010; NIIF_NONE = 0x00000000; NIIF_INFO = 0x00000001; NIIF_WARNING = 0x00000002; NIIF_ERROR = 0x00000003; NIIF_USER = 0x00000004; NIIF_NOSOUND = 0x00000010; NIIF_LARGE_ICON = 0x00000020; NIIF_RESPECT_QUIET_TIME = 0x00000080; NIM_SETVERSION =0x00000004; NIM_SETFOCUS = 0x00000003; NIM_ADD = 0x00000000; NIM_DELETE = 0x00000002; NIM_MODIFY = 0x00000001; NIS_HIDDEN = 0x00000001; NOTIFYICON_VERSION = 3; TC_CBACK = 0x4DE; WM_LBUTTONDOWN = 0x0201; WM_LBUTTONUP = 0x0202; WM_RBUTTONDOWN = 0x0204; WM_RBUTTONUP = 0x0205; WM_DESTROY = 0x0002; HWND = INT; HICON = INT; TCHAR = STRING; GUID = INT; NOTIFYICONDATA = MemoryEx.DefineStruct{ DWORD "cbSize"; HWND "hWnd"; UINT "uID"; UINT "uFlags"; UINT "uCallbackMessage"; HICON "hIcon"; TCHAR ("szTip",128,1,MEMEX_ASCII); DWORD "dwState"; DWORD "dwStateMask"; TCHAR ("szInfo",256,1,MEMEX_ASCII); UNION { UINT "uTimeout"; UINT "uVersion"; }; TCHAR ("szInfoTitle",256,1,MEMEX_ASCII); DWORD "dwInfoFlags"; GUID "guidItem"; HICON "hBalloonIcon"; }; Tray = {} Tray.CreateHost = function() local I = User32.CreateWindowExA(0,"Edit","",1342308359,1,1,0,0,Application.GetWndHandle(),0,0,0) if I and (type(I) ~= "number") then return false, "Can't create callback" else local s = Subclass.Create(I, function(hWnd,uMsg,wParam,lParam) if(uMsg == WM_DESTROY)then Subclass.Remove(I); return 0 end if(uMsg == TC_CBACK)then local M = System.GetMousePosition(false,nil) if lParam == WM_LBUTTONDOWN then Tray.OnLeftButton(wParam,false,M.X,M.Y) Tray.SetFocus(wParam) elseif lParam == WM_LBUTTONUP then Tray.OnLeftButton(wParam,true,M.X,M.Y) Tray.SetFocus(wParam) elseif lParam == WM_RBUTTONDOWN then Tray.OnRightButton(wParam,false,M.X,M.Y) Tray.SetFocus(wParam) elseif lParam == WM_RBUTTONUP then Tray.OnRightButton(wParam,true,M.X,M.Y) Tray.SetFocus(wParam) end return 0 end return Subclass.OldWinProc(hWnd,uMsg,wParam,lParam); end) Tray.HostHandle = I return true, I end end; Tray.SetFocus = function(iID) local lpBuff = MemoryEx.Allocate(MemoryEx.StructSize(NOTIFYICONDATA) + 100); if(lpBuff)then hStruct = MemoryEx.AssignStruct(lpBuff + 50,NOTIFYICONDATA); if(hStruct)then hStruct.hWnd = Tray.HostHandle; hStruct.uID = iID; hStruct.uFlags = NIF_MESSAGE; hStruct.uCallbackMessage = TC_CBACK; hStruct.hIcon = Ih; hStruct.szTip = ""; hStruct.dwState = NIS_HIDDEN; hStruct.dwStateMask = NIS_HIDDEN; hStruct.szInfo = ""; hStruct.uTimeout = 0; hStruct.uVersion = NOTIFYICON_VERSION; hStruct.szInfoTitle = ""; hStruct.dwInfoFlags = NIIF_NONE; hStruct.guidItem = 0; hStruct.hBalloonIcon = ""; hStruct.cbSize = Tray.MainStructSize or hStruct:Size(); else MemoryEx.Free(lpBuff) end else return false end local poi = hStruct:GetPointer(); if tonumber(Shell32.Shell_NotifyIcon(NIM_SETFOCUS,poi)) == 0 then MemoryEx.Free(lpBuff); hStruct:Close(); return false else MemoryEx.Free(lpBuff); hStruct:Close(); return true end end; Tray.FreeIcon = function(sIcon) local hIcon = User32.DestroyIcon(sIcon) if hIcon ~= 0 then return true, "OK" else return false, "Can't destroy icon" end end; Tray.LoadIcon = function(sIcon) local hIcon = User32.LoadImageA(0,sIcon,IMAGE_ICON,0,0,LR_LOADFROMFILE) if (hIcon ~= nil and hIcon > 0) then return true, hIcon else return false, "Can't load icon" end end; Tray.DllVersionInfo = function() local OS = System.GetOSName(); if OS == "" then return false, "Can't determine OS" end if OS == "Windows XP" or OS == "Windows Server 2003" then Tray.MainStructSize = NOTIFYICON_VERSION end Tray.OSName = OS Tray.VersionSet = 1 return true, "OK" end; Tray.OnLeftButton = function(nTrayID,bState,xPos,yPos) if bState then local t ={} t[1] = {}; t[1].Text = "Left Button ID: "..nTrayID; Application.ShowPopupMenu(xPos,yPos,t,8,32,true,false) else --Button down click end end Tray.OnRightButton = function(nTrayID,bState,xPos,yPos) if bState then local t ={} t[1] = {}; t[1].Text = "Right Button ID: "..nTrayID; Application.ShowPopupMenu(xPos,yPos,t,8,32,true,false) else --Button down click end end Tray.OnBalloon = function() end Tray.CreateTrayIcon = function(iID,sIcon,sTool) if Tray.HostHandle ~= 1 then local x,y = Tray.CreateHost() if not x then return false, y end end if Tray.VersionSet ~= 1 then local x,y = Tray.DllVersionInfo() if not x then return false, y end end local x,Ih = Tray.LoadIcon(sIcon) if not x then return false, Ih end local lpBuff = MemoryEx.Allocate(MemoryEx.StructSize(NOTIFYICONDATA) + 100); if(lpBuff)then hStruct = MemoryEx.AssignStruct(lpBuff + 50,NOTIFYICONDATA); if(hStruct)then hStruct.hWnd = Tray.HostHandle; hStruct.uID = iID; hStruct.uFlags = NIF_MESSAGE + NIF_ICON + NIF_TIP; hStruct.uCallbackMessage = TC_CBACK; hStruct.hIcon = Ih; hStruct.szTip = sTool; hStruct.dwState = NIS_HIDDEN; hStruct.dwStateMask = NIS_HIDDEN; hStruct.szInfo = ""; hStruct.uTimeout = 0; hStruct.uVersion = NOTIFYICON_VERSION; hStruct.szInfoTitle = ""; hStruct.dwInfoFlags = NIIF_NONE; hStruct.guidItem = 0; hStruct.hBalloonIcon = ""; hStruct.cbSize = Tray.MainStructSize or hStruct:Size(); else MemoryEx.Free(lpBuff); return false, "Can't open structure" end else return false, "Can't create buffer" end local poi = hStruct:GetPointer(); if tonumber(Shell32.Shell_NotifyIcon(NIM_ADD,poi)) == 0 then MemoryEx.Free(lpBuff); hStruct:Close(); Tray.FreeIcon(Ih); return false, "Create tray icon failed" else Shell32.Shell_NotifyIcon(NIM_SETVERSION,poi) MemoryEx.Free(lpBuff); hStruct:Close(); Tray.FreeIcon(Ih); return true, "OK" end end; Tray.SetToolTip = function(iID,tip) local lpBuff = MemoryEx.Allocate(MemoryEx.StructSize(NOTIFYICONDATA) + 100); if(lpBuff)then hStruct = MemoryEx.AssignStruct(lpBuff + 50,NOTIFYICONDATA); if(hStruct)then hStruct.hWnd = Tray.HostHandle; hStruct.uID = iID; hStruct.uFlags = NIF_TIP; hStruct.uCallbackMessage = TC_CBACK; hStruct.hIcon = Ih; hStruct.szTip = tip; hStruct.dwState = NIS_HIDDEN; hStruct.dwStateMask = NIS_HIDDEN; hStruct.szInfo = ""; hStruct.uTimeout = 0; hStruct.uVersion = NOTIFYICON_VERSION; hStruct.szInfoTitle = ""; hStruct.dwInfoFlags = NIIF_NONE; hStruct.guidItem = 0; hStruct.hBalloonIcon = ""; hStruct.cbSize = Tray.MainStructSize or hStruct:Size(); else MemoryEx.Free(lpBuff); return false, "Can't open structure" end else return false, "Can't create buffer" end local poi = hStruct:GetPointer(); if tonumber(Shell32.Shell_NotifyIcon(NIM_MODIFY,poi)) == 0 then MemoryEx.Free(lpBuff); hStruct:Close(); return false, "Set tool tip failed" else MemoryEx.Free(lpBuff); hStruct:Close(); return true, "OK" end end; Tray.ShowBalloon = function(iID,sTitle,sMessage) local lpBuff = MemoryEx.Allocate(MemoryEx.StructSize(NOTIFYICONDATA) + 100); if(lpBuff)then hStruct = MemoryEx.AssignStruct(lpBuff + 50,NOTIFYICONDATA); if(hStruct)then hStruct.cbSize = Tray.MainStructSize or hStruct:Size(); hStruct.hWnd = Tray.HostHandle; hStruct.uID = iID; hStruct.uFlags = NIF_MESSAGE + NIF_INFO; hStruct.uCallbackMessage = TC_CBACK; hStruct.hIcon = NIIF_NONE; hStruct.szTip = sTool; hStruct.dwState = NIS_HIDDEN; hStruct.dwStateMask = NIS_HIDDEN; hStruct.szInfo = sMessage; hStruct.uTimeout = 10000; hStruct.uVersion = NOTIFYICON_VERSION; hStruct.szInfoTitle = sTitle; hStruct.dwInfoFlags = NIIF_NONE; hStruct.guidItem = 0; hStruct.hBalloonIcon = NIIF_NONE; else MemoryEx.Free(lpBuff); return false, "Can't open structure" end else return false, "Can't create buffer" end if tonumber(Shell32.Shell_NotifyIcon(NIM_MODIFY, hStruct:GetPointer())) == 0 then MemoryEx.Free(lpBuff); hStruct:Close(); return false, "Show balloon failed" else MemoryEx.Free(lpBuff); hStruct:Close(); return true, "OK" end end; Tray.DeleteTrayIcon = function(iID) local lpBuff = MemoryEx.Allocate(MemoryEx.StructSize(NOTIFYICONDATA) + 100); if(lpBuff)then hStruct = MemoryEx.AssignStruct(lpBuff + 50,NOTIFYICONDATA); if(hStruct)then hStruct.hWnd = Tray.HostHandle; hStruct.uID = iID; hStruct.uFlags = NIF_MESSAGE + NIF_ICON; hStruct.uCallbackMessage = TC_CBACK; hStruct.hIcon = Ih; hStruct.szTip = ""; hStruct.dwState = NIS_HIDDEN; hStruct.dwStateMask = NIS_HIDDEN; hStruct.szInfo = ""; hStruct.uTimeout = 0; hStruct.uVersion = NOTIFYICON_VERSION; hStruct.szInfoTitle = ""; hStruct.dwInfoFlags = NIIF_NONE; hStruct.guidItem = 0; hStruct.hBalloonIcon = ""; hStruct.cbSize = Tray.MainStructSize or hStruct:Size(); else MemoryEx.Free(lpBuff); return false, "Can't open structure" end else return false, "Can't create buffer" end local poi = hStruct:GetPointer(); if tonumber(Shell32.Shell_NotifyIcon(NIM_DELETE,poi)) == 0 then MemoryEx.Free(lpBuff); hStruct:Close(); return false, "Delete tray icon failed" else MemoryEx.Free(lpBuff); hStruct:Close(); return true, "OK" end end; Tray.ChangeIcon = function(iID,sIcon) local x,Ih = Tray.LoadIcon(sIcon) if not x then return false, Ih end local lpBuff = MemoryEx.Allocate(MemoryEx.StructSize(NOTIFYICONDATA) + 100); if(lpBuff)then hStruct = MemoryEx.AssignStruct(lpBuff + 50,NOTIFYICONDATA); if(hStruct)then hStruct.hWnd = Tray.HostHandle; hStruct.uID = iID; hStruct.uFlags = NIF_MESSAGE + NIF_ICON; hStruct.uCallbackMessage = TC_CBACK; hStruct.hIcon = Ih; hStruct.szTip = tip; hStruct.dwState = NIS_HIDDEN; hStruct.dwStateMask = NIS_HIDDEN; hStruct.szInfo = ""; hStruct.uTimeout = 0; hStruct.uVersion = NOTIFYICON_VERSION; hStruct.szInfoTitle = ""; hStruct.dwInfoFlags = NIIF_NONE; hStruct.guidItem = 0; hStruct.hBalloonIcon = ""; hStruct.cbSize = Tray.MainStructSize or hStruct:Size(); else MemoryEx.Free(lpBuff); return false, "Can't open structure" end else return false, "Can't create buffer" end local poi = hStruct:GetPointer(); if tonumber(Shell32.Shell_NotifyIcon(NIM_MODIFY,poi)) == 0 then MemoryEx.Free(lpBuff); hStruct:Close(); Tray.FreeIcon(Ih); return false, "Change icon failed" else MemoryEx.Free(lpBuff); hStruct:Close(); Tray.FreeIcon(Ih); return true, "OK" end end; --On Show local x,err = Tray.CreateTrayIcon(101,_SourceFolder.."\\Autoplay\\Icons\\1.ico","Notification Icon 1") if not x then Dialog.Message("",err) end --Button On Click local x, y = Tray.ShowBalloon(101,"Test Title","Test Message") Dialog.Message("",y) --Refrences --[[ http://msdn.microsoft.com/en-us/library/windows/desktop/bb762159%28v=vs.85%29.aspx http://msdn.microsoft.com/en-us/library/windows/desktop/bb773352%28v=vs.85%29.aspx --]]
--Global Shell32 = Library.Load("Shell32.dll"); User32 = Library.Load("user32.dll"); NIIF_NONE = 0x00000000; NIIF_INFO = 0x00000001; NIIF_WARNING = 0x00000002; NIIF_ERROR = 0x00000003; NIIF_USER = 0x00000004; NIF_MESSAGE = 0x00000001; NIF_ICON = 0x00000002; NIF_TIP = 0x00000004; NIF_INFO = 0x00000010; NIM_SETVERSION =0x00000004; NIM_SETFOCUS = 0x00000003; NIM_ADD = 0x00000000; NIM_DELETE = 0x00000002; NIM_MODIFY = 0x00000001; NIS_HIDDEN = 0x00000001; HWND = INT; HICON = INT; TCHAR = STRING; GUID = INT; NOTIFYICONDATA = MemoryEx.DefineStruct{ DWORD "cbSize"; HWND "hWnd"; UINT "uID"; UINT "uFlags"; UINT "uCallbackMessage"; HICON "hIcon"; TCHAR ("szTip",128,1,MEMEX_ASCII); DWORD "dwState"; DWORD "dwStateMask"; TCHAR ("szInfo",256,1,MEMEX_ASCII); UNION { UINT "uTimeout"; UINT "uVersion"; }; TCHAR ("szInfoTitle",256,1,MEMEX_ASCII); DWORD "dwInfoFlags"; GUID "guidItem"; HICON "hBalloonIcon"; }; Tray = {} Tray.CreateHost = function() local I = User32.CreateWindowExA(0,"Edit","",1342308359,1,1,0,0,Application.GetWndHandle(),0,0,0) if I and (type(I) ~= "number") then return false, "Can't create callback" else local s = Subclass.Create(I, function(hWnd,uMsg,wParam,lParam) if(uMsg == 0x0002)then Subclass.Remove(I); return 0 end if(uMsg == 0x4DE)then local M = System.GetMousePosition(false,nil) if lParam == 0x0201 then Tray.OnLeftButton(wParam,false,M.X,M.Y) elseif lParam == 0x0202 then Tray.OnLeftButton(wParam,true,M.X,M.Y) elseif lParam == 0x0204 then Tray.OnRightButton(wParam,false,M.X,M.Y) elseif lParam == 0x0205 then Tray.OnRightButton(wParam,true,M.X,M.Y) elseif lParam == 1029 then Tray.OnBalloon(wParam,M.X,M.Y) end return 0 end return Subclass.OldWinProc(hWnd,uMsg,wParam,lParam); end) Tray.HostHandle = I return true, I end end; Tray.SetFocus = function(iID) local lpBuff = MemoryEx.Allocate(MemoryEx.StructSize(NOTIFYICONDATA) + 100); if(lpBuff)then hStruct = MemoryEx.AssignStruct(lpBuff + 50,NOTIFYICONDATA); if(hStruct)then hStruct.hWnd = Tray.HostHandle; hStruct.uID = iID; hStruct.uFlags = NIF_MESSAGE; hStruct.uCallbackMessage = 0x4DE; hStruct.hIcon = Ih; hStruct.szTip = ""; hStruct.dwState = NIS_HIDDEN; hStruct.dwStateMask = NIS_HIDDEN; hStruct.szInfo = ""; hStruct.uTimeout = 0; hStruct.uVersion = 3; hStruct.szInfoTitle = ""; hStruct.dwInfoFlags = NIIF_NONE; hStruct.guidItem = 0; hStruct.hBalloonIcon = ""; hStruct.cbSize = 504; else MemoryEx.Free(lpBuff) end else return false end local poi = hStruct:GetPointer(); if tonumber(Shell32.Shell_NotifyIcon(NIM_SETFOCUS,poi)) == 0 then MemoryEx.Free(lpBuff); hStruct:Close(); return false else MemoryEx.Free(lpBuff); hStruct:Close(); return true end end; Tray.FreeIcon = function(sIcon) local hIcon = User32.DestroyIcon(sIcon) if hIcon ~= 0 then return true, "OK" else return false, "Can't destroy icon" end end; Tray.LoadIcon = function(sIcon) local hIcon = User32.LoadImageA(0,sIcon,1,0,0,0x0010) if (hIcon ~= nil and hIcon > 0) then return true, hIcon else return false, "Can't load icon" end end; Tray.DllVersionInfo = function() local OS = System.GetOSName(); if OS == "" then return false, "Can't determine OS" end Tray.OSName = OS Tray.VersionSet = 1 return true, "OK" end; Tray.OnLeftButton = function(nTrayID,bState,xPos,yPos) if bState then --Button Up else --Button Down end end Tray.OnRightButton = function(nTrayID,bState,xPos,yPos) if bState then --Button Up else --Button Down end end Tray.OnBalloon = function(nTrayID,xPos,yPos) Dialog.Message(nTrayID,"Balloon Clicked") end Tray.CreateTrayIcon = function(iID,sIcon,sTool) if Tray.HostHandle ~= 1 then local x,y = Tray.CreateHost() if not x then return false, y end end if Tray.VersionSet ~= 1 then local x,y = Tray.DllVersionInfo() if not x then return false, y end end local x,Ih = Tray.LoadIcon(sIcon) if not x then return false, Ih end local lpBuff = MemoryEx.Allocate(MemoryEx.StructSize(NOTIFYICONDATA) + 100); if(lpBuff)then hStruct = MemoryEx.AssignStruct(lpBuff + 50,NOTIFYICONDATA); if(hStruct)then hStruct.hWnd = Tray.HostHandle; hStruct.uID = iID; hStruct.uFlags = NIF_MESSAGE + NIF_ICON + NIF_TIP; hStruct.uCallbackMessage = 0x4DE; hStruct.hIcon = Ih; hStruct.szTip = sTool; hStruct.dwState = NIS_HIDDEN; hStruct.dwStateMask = NIS_HIDDEN; hStruct.szInfo = ""; hStruct.uTimeout = 0; hStruct.uVersion = 3; hStruct.szInfoTitle = ""; hStruct.dwInfoFlags = NIIF_NONE; hStruct.guidItem = 0; hStruct.hBalloonIcon = ""; hStruct.cbSize = 504; else MemoryEx.Free(lpBuff); return false, "Can't open structure" end else return false, "Can't create buffer" end local poi = hStruct:GetPointer(); if tonumber(Shell32.Shell_NotifyIcon(NIM_ADD,poi)) == 0 then MemoryEx.Free(lpBuff); hStruct:Close(); Tray.FreeIcon(Ih); return false, "Create tray icon failed" else Shell32.Shell_NotifyIcon(NIM_SETVERSION,poi) MemoryEx.Free(lpBuff); hStruct:Close(); Tray.FreeIcon(Ih); return true, "OK" end end; Tray.SetToolTip = function(iID,tip) local lpBuff = MemoryEx.Allocate(MemoryEx.StructSize(NOTIFYICONDATA) + 100); if(lpBuff)then hStruct = MemoryEx.AssignStruct(lpBuff + 50,NOTIFYICONDATA); if(hStruct)then hStruct.hWnd = Tray.HostHandle; hStruct.uID = iID; hStruct.uFlags = NIF_TIP; hStruct.uCallbackMessage = 0x4DE; hStruct.hIcon = Ih; hStruct.szTip = tip; hStruct.dwState = NIS_HIDDEN; hStruct.dwStateMask = NIS_HIDDEN; hStruct.szInfo = ""; hStruct.uTimeout = 0; hStruct.uVersion = 3; hStruct.szInfoTitle = ""; hStruct.dwInfoFlags = NIIF_NONE; hStruct.guidItem = 0; hStruct.hBalloonIcon = ""; hStruct.cbSize = 504; else MemoryEx.Free(lpBuff); return false, "Can't open structure" end else return false, "Can't create buffer" end local poi = hStruct:GetPointer(); if tonumber(Shell32.Shell_NotifyIcon(NIM_MODIFY,poi)) == 0 then MemoryEx.Free(lpBuff); hStruct:Close(); return false, "Set tool tip failed" else MemoryEx.Free(lpBuff); hStruct:Close(); return true, "OK" end end; Tray.ShowBalloon = function(iID,sTitle,sMessage,Icon) local lpBuff = MemoryEx.Allocate(MemoryEx.StructSize(NOTIFYICONDATA) + 100); if(lpBuff)then hStruct = MemoryEx.AssignStruct(lpBuff + 50,NOTIFYICONDATA); if(hStruct)then local NIIF_NOSOUND = 0x00000010; local NIIF_LARGE_ICON = 0x00000020; local NIIF_RESPECT_QUIET_TIME = 0x00000080; hStruct.hWnd = Tray.HostHandle; hStruct.uID = iID; hStruct.uFlags = NIF_INFO + NIF_ICON hStruct.uCallbackMessage = 0x4DE; hStruct.hIcon = Icon; hStruct.szTip = 0; hStruct.dwState = NIS_HIDDEN; hStruct.dwStateMask = NIS_HIDDEN; hStruct.szInfo = sMessage; hStruct.uTimeout = 120000; hStruct.uVersion = 3; hStruct.szInfoTitle = sTitle; hStruct.dwInfoFlags = NIIF_USER; hStruct.guidItem = 0; hStruct.hBalloonIcon = Icon; hStruct.cbSize = 504; else MemoryEx.Free(lpBuff); return false, "Can't open structure" end else return false, "Can't create buffer" end if tonumber(Shell32.Shell_NotifyIcon(NIM_MODIFY,hStruct:GetPointer())) == 0 then MemoryEx.Free(lpBuff); hStruct:Close(); return false, "Show balloon failed" else MemoryEx.Free(lpBuff); hStruct:Close(); return true, "OK" end end; Tray.DeleteTrayIcon = function(iID) local lpBuff = MemoryEx.Allocate(MemoryEx.StructSize(NOTIFYICONDATA) + 100); if(lpBuff)then hStruct = MemoryEx.AssignStruct(lpBuff + 50,NOTIFYICONDATA); if(hStruct)then hStruct.hWnd = Tray.HostHandle; hStruct.uID = iID; hStruct.uFlags = NIF_MESSAGE + NIF_ICON; hStruct.uCallbackMessage = 0x4DE; hStruct.hIcon = Ih; hStruct.szTip = ""; hStruct.dwState = NIS_HIDDEN; hStruct.dwStateMask = NIS_HIDDEN; hStruct.szInfo = ""; hStruct.uTimeout = 0; hStruct.uVersion = 3; hStruct.szInfoTitle = ""; hStruct.dwInfoFlags = NIIF_NONE; hStruct.guidItem = 0; hStruct.hBalloonIcon = ""; hStruct.cbSize = 504; else MemoryEx.Free(lpBuff); return false, "Can't open structure" end else return false, "Can't create buffer" end local poi = hStruct:GetPointer(); if tonumber(Shell32.Shell_NotifyIcon(NIM_DELETE,poi)) == 0 then MemoryEx.Free(lpBuff); hStruct:Close(); return false, "Delete tray icon failed" else MemoryEx.Free(lpBuff); hStruct:Close(); return true, "OK" end end; Tray.ChangeIcon = function(iID,sIcon) local x,Ih = Tray.LoadIcon(sIcon) if not x then return false, Ih end local lpBuff = MemoryEx.Allocate(MemoryEx.StructSize(NOTIFYICONDATA) + 100); if(lpBuff)then hStruct = MemoryEx.AssignStruct(lpBuff + 50,NOTIFYICONDATA); if(hStruct)then hStruct.hWnd = Tray.HostHandle; hStruct.uID = iID; hStruct.uFlags = NIF_MESSAGE + NIF_ICON; hStruct.uCallbackMessage = 0x4DE; hStruct.hIcon = Ih; hStruct.szTip = tip; hStruct.dwState = NIS_HIDDEN; hStruct.dwStateMask = NIS_HIDDEN; hStruct.szInfo = ""; hStruct.uTimeout = 0; hStruct.uVersion = 3; hStruct.szInfoTitle = ""; hStruct.dwInfoFlags = NIIF_NONE; hStruct.guidItem = 0; hStruct.hBalloonIcon = ""; hStruct.cbSize = 504; else MemoryEx.Free(lpBuff); return false, "Can't open structure" end else return false, "Can't create buffer" end local poi = hStruct:GetPointer(); if tonumber(Shell32.Shell_NotifyIcon(NIM_MODIFY,poi)) == 0 then MemoryEx.Free(lpBuff); hStruct:Close(); Tray.FreeIcon(Ih); return false, "Change icon failed" else MemoryEx.Free(lpBuff); hStruct:Close(); Tray.FreeIcon(Ih); return true, "OK" end end; --On Show local x,err = Tray.CreateTrayIcon(101,_SourceFolder.."\\Autoplay\\Icons\\1.ico","Notification Icon 1") if not x then Dialog.Message("",err) end --Button On Click local x, Ico = Tray.LoadIcon(_SourceFolder.."\\Autoplay\\Icons\\1.ico") if x then local x, y = Tray.ShowBalloon(101,"Test Title","Test Message",Ico) end --Refrences --[[ http://msdn.microsoft.com/en-us/library/windows/desktop/bb762159%28v=vs.85%29.aspx http://msdn.microsoft.com/en-us/library/windows/desktop/bb773352%28v=vs.85%29.aspx --]]
NIIF_NONE = 0x00000000; NIIF_INFO = 0x00000001; NIIF_WARNING = 0x00000002; NIIF_ERROR = 0x00000003;
NIIF_USER = 0x00000004;
Comment