Announcement

Collapse
No announcement yet.

Notification Icon

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • #46
    Code:
    -- Global
    Shell32 = Library.Load("Shell32.dll");
    User32 = Library.Load("user32.dll");
    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 = {}
    -- Internal Functions
    Tray.CreateHost = function()
     Tray.OSName = System.GetOSName();
     if OS == "" then
      return false, "Can't determine OS"
     end
     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 == 1024 then
        Tray.OnBalloonShow(wParam,M.X,M.Y)
       elseif lParam == 1027 then
        Tray.OnBalloonHide(wParam,M.X,M.Y)
       elseif lParam == 1028 then
        Tray.OnBalloonTimeOut(wParam,M.X,M.Y)
       elseif lParam == 1029 then
        Tray.OnBalloonClick(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;
    -- Icon Functions
    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;
    -- Main Functions
    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
     local x,Ih = Tray.LoadIcon(sIcon)
     if not x then
      return false, Ih
     end
     local B = MemoryEx.Allocate(MemoryEx.StructSize(NOTIFYICONDATA) + 100);
     if(B)then
      S = MemoryEx.AssignStruct(B + 50,NOTIFYICONDATA);
      if(S)then
       S.hWnd = Tray.HostHandle;
       S.uID = iID;
       S.uFlags = 0x7;
       S.uCallbackMessage = 0x4DE;
       S.hIcon = Ih;
       S.szTip = sTool;
       S.dwState = 0x00000001;
       S.dwStateMask = 0x00000001;
       S.szInfo = "";
       S.uTimeout = 0;
       S.uVersion = 3;
       S.szInfoTitle = "";
       S.dwInfoFlags = 0x00000000;
       S.guidItem = 0;
       S.hBalloonIcon = "";
       S.cbSize = 504;
      else
       MemoryEx.Free(B);
       return false, "Can't open structure"
      end
     else
      return false, "Can't create buffer"
     end
     local poi = S:GetPointer();
     if tonumber(Shell32.Shell_NotifyIcon(0x00000000,poi)) == 0 then
      MemoryEx.Free(B);
      S:Close();
      Tray.FreeIcon(Ih);
      return false, "Create tray icon failed"
     else
      Shell32.Shell_NotifyIcon(0x00000004,poi)
      MemoryEx.Free(B);
      S:Close();
      Tray.FreeIcon(Ih);
      return true, "OK"
     end
    end;
    Tray.DeleteTrayIcon = function(iID)
     local B = MemoryEx.Allocate(MemoryEx.StructSize(NOTIFYICONDATA) + 100);
     if(B)then
      S = MemoryEx.AssignStruct(B + 50,NOTIFYICONDATA);
      if(S)then
       S.hWnd = Tray.HostHandle;
       S.uID = iID;
       S.uFlags = 0x3;
       S.uCallbackMessage = 0x4DE;
       S.hIcon = Ih;
       S.szTip = "";
       S.dwState = 0x00000001;
       S.dwStateMask = 0x00000001;
       S.szInfo = "";
       S.uTimeout = 0;
       S.uVersion = 3;
       S.szInfoTitle = "";
       S.dwInfoFlags = 0x00000000;
       S.guidItem = 0;
       S.hBalloonIcon = "";
       S.cbSize = 504;
      else
       MemoryEx.Free(B);
       return false, "Can't open structure"
      end
     else
      return false, "Can't create buffer"
     end
     local poi = S:GetPointer();
     if tonumber(Shell32.Shell_NotifyIcon(0x00000002,poi)) == 0 then
      MemoryEx.Free(B);
      S:Close();
      return false, "Delete tray icon failed"
     else
      MemoryEx.Free(B);
      S:Close();
      return true, "OK"
     end
    end;
    Tray.SetToolTip = function(iID,tip)
     local B = MemoryEx.Allocate(MemoryEx.StructSize(NOTIFYICONDATA) + 100);
     if(B)then
      S = MemoryEx.AssignStruct(B + 50,NOTIFYICONDATA);
      if(S)then
       S.hWnd = Tray.HostHandle;
       S.uID = iID;
       S.uFlags = 0x00000004;
       S.uCallbackMessage = 0x4DE;
       S.hIcon = Ih;
       S.szTip = tip;
       S.dwState = 0x00000001;
       S.dwStateMask = 0x00000001;
       S.szInfo = "";
       S.uTimeout = 0;
       S.uVersion = 3;
       S.szInfoTitle = "";
       S.dwInfoFlags = 0x00000000;
       S.guidItem = 0;
       S.hBalloonIcon = "";
       S.cbSize = 504;
      else
       MemoryEx.Free(B);
       return false, "Can't open structure"
      end
     else
      return false, "Can't create buffer"
     end
     local poi = S:GetPointer();
     if tonumber(Shell32.Shell_NotifyIcon(0x00000001,poi)) == 0 then
      MemoryEx.Free(B);
      S:Close();
      return false, "Set tool tip failed"
     else
      MemoryEx.Free(B);
      S: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 B = MemoryEx.Allocate(MemoryEx.StructSize(NOTIFYICONDATA) + 100);
     if(B)then
      S = MemoryEx.AssignStruct(B + 50,NOTIFYICONDATA);
      if(S)then
       S.hWnd = Tray.HostHandle;
       S.uID = iID;
       S.uFlags = 0x3;
       S.uCallbackMessage = 0x4DE;
       S.hIcon = Ih;
       S.szTip = tip;
       S.dwState = 0x00000001;
       S.dwStateMask = 0x00000001;
       S.szInfo = "";
       S.uTimeout = 0;
       S.uVersion = 3;
       S.szInfoTitle = "";
       S.dwInfoFlags = 0x00000000;
       S.guidItem = 0;
       S.hBalloonIcon = "";
       S.cbSize = 504;
      else
       MemoryEx.Free(B);
       return false, "Can't open structure"
      end
     else
      return false, "Can't create buffer"
     end
     local poi = S:GetPointer();
     if tonumber(Shell32.Shell_NotifyIcon(0x00000001,poi)) == 0 then
      MemoryEx.Free(B);
      S:Close();
      Tray.FreeIcon(Ih);
      return false, "Change icon failed"
     else
      MemoryEx.Free(B);
      S:Close();
      Tray.FreeIcon(Ih);
      return true, "OK"
     end
    end;
    Tray.ShowBalloon = function(iID,sTitle,sMessage,Icon)
     local B = MemoryEx.Allocate(MemoryEx.StructSize(NOTIFYICONDATA) + 100);
     if(B)then
      S = MemoryEx.AssignStruct(B + 50,NOTIFYICONDATA);
      if(S)then
       --[[
       local NIIF_NOSOUND = 0x00000010;
       local NIIF_LARGE_ICON = 0x00000020;
       local NIIF_RESPECT_QUIET_TIME = 0x00000080;
       local NIIF_INFO = 0x00000001;
       local NIIF_WARNING = 0x00000002;
       local NIIF_ERROR = 0x00000003;
       local NIIF_USER = 0x00000004;
       --]]
       S.hWnd = Tray.HostHandle;
       S.uID = iID;
       S.uFlags = 0x00000010
       S.uCallbackMessage = 0x4DE;
       S.hIcon = Icon;
       S.szTip = 0;
       S.dwState = 0x00000001;
       S.dwStateMask = 0x00000001;
       S.szInfo = sMessage;
       S.uTimeout = 120000;
       S.uVersion = 3;
       S.szInfoTitle = sTitle;
       S.dwInfoFlags = 0x00000004;
       S.guidItem = 0;
       S.hBalloonIcon = Icon;
       S.cbSize = 504;
      else
       MemoryEx.Free(B);
       return false, "Can't open structure"
      end
     else
      return false, "Can't create buffer"
     end
     if tonumber(Shell32.Shell_NotifyIcon(0x00000001,S:GetPointer())) == 0 then
      MemoryEx.Free(B);
      S:Close();
      return false, "Show balloon failed"
     else
      MemoryEx.Free(B);
      S:Close();
      return true, "OK"
     end
    end;
    Tray.SetFocus = function(iID)
     local B = MemoryEx.Allocate(MemoryEx.StructSize(NOTIFYICONDATA) + 100);
     if(B)then
      S = MemoryEx.AssignStruct(B + 50,NOTIFYICONDATA);
      if(S)then
       S.hWnd = Tray.HostHandle;
       S.uID = iID;
       S.uFlags = 0x00000001;
       S.uCallbackMessage = 0x4DE;
       S.hIcon = Ih;
       S.szTip = "";
       S.dwState = 0x00000001;
       S.dwStateMask = 0x00000001;
       S.szInfo = "";
       S.uTimeout = 0;
       S.uVersion = 3;
       S.szInfoTitle = "";
       S.dwInfoFlags = 0x00000000;
       S.guidItem = 0;
       S.hBalloonIcon = "";
       S.cbSize = 504;
      else
       MemoryEx.Free(B)
      end
     else
      return false
     end
     local poi = S:GetPointer();
     if tonumber(Shell32.Shell_NotifyIcon(0x00000003,poi)) == 0 then
      MemoryEx.Free(B);
      S:Close();
      return false
     else
      MemoryEx.Free(B);
      S:Close();
      return true
     end
    end;
    -- CallBack Functions
    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.OnBalloonShow = function(nTrayID,xPos,yPos)
     -- Only used if the balloon was queued
    end
    Tray.OnBalloonHide = function(nTrayID,xPos,yPos)
     --The balloon has disappeared, not sent if the balloon is dismissed due to a timeout or mouse click
    end
    Tray.OnBalloonTimeOut = function(nTrayID,xPos,yPos)
     --The balloon is dismissed because of a timeout
    end
    Tray.OnBalloonClick = function(nTrayID,xPos,yPos)
     --The balloon is dismissed because a mouse click
    end
    --[[
    
      -- Refrences
    
      [url]http://msdn.microsoft.com/en-us/library/windows/desktop/bb762159%28v=vs.85%29.aspx[/url]
      [url]http://msdn.microsoft.com/en-us/library/windows/desktop/bb773352%28v=vs.85%29.aspx[/url]
    
      -- Sample Usage
    
       -- On Show
    
       NICO1, Err = Tray.CreateTrayIcon(101,_SourceFolder.."\\Autoplay\\Icons\\1.ico","ID: 101")
       if not NICO1 then
        Dialog.Message("", Err)
       end
    
       -- Button On Click
    
       if NICO1 then
        local x, Ico = Tray.LoadIcon(_SourceFolder.."\\Autoplay\\Icons\\1.ico")
        if x then
         Tray.ShowBalloon(101,"Test Title","Test Message",Ico)
        end
       end
    
       -- On Button Right Click
    
       if NICO1 then
        Tray.SetToolTip(101,"New Tooltip ID: 101")
       end
    
       -- On ShutDown
    
       if NICO1 then
        Tray.DeleteTrayIcon(101)
       end
    
    --]]
    Bit of an update, more balloon events added, still no icons though...................

    Comment


    • #47
      Code:
      -- Global Functions
      Shell32Library = Library.Load("Shell32.dll");
      User32Library = Library.Load("User32.dll");
      TBPF_NOPROGRESS = 0x00000000;
      TBPF_INDETERMINATE = 0x00000001;
      TBPF_NORMAL = 0x00000002;
      TBPF_ERROR = 0x00000004;
      TBPF_PAUSED = 0x00000008;
      NIIF_NONE = 0x00000000;
      NIIF_INFO = 0x00000001;
      NIIF_WARNING = 0x00000002;
      NIIF_ERROR = 0x00000003;
      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",64,1,MEMEX_ASCII);
       DWORD "dwInfoFlags";
       GUID  "guidItem";
       HICON "hBalloonIcon";
      };
      TrayIcon = {
       -- Internal Functions
      CreateHost = function()
       TrayIcon.OSName = System.GetOSName();
       if OS == "" then
        return false, "Can't determine OS"
       end
       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 == 0x0002)then
         Subclass.Remove(I);
         return 0
        end
        if(uMsg == 0x4DE)then
         local M = System.GetMousePosition(false,nil)
         if M ~= nil then
          if lParam == 0x0201 then
           TrayIcon.OnLeftButton(wParam,false,M.X,M.Y)
          elseif lParam == 0x0202 then
           TrayIcon.OnLeftButton(wParam,true,M.X,M.Y)
          elseif lParam == 0x0204 then
           TrayIcon.OnRightButton(wParam,false,M.X,M.Y)
          elseif lParam == 0x0205 then
           TrayIcon.OnRightButton(wParam,true,M.X,M.Y)
          elseif lParam == 1024 then
           TrayIcon.OnBalloonShow(wParam,M.X,M.Y)
          elseif lParam == 1027 then
           TrayIcon.OnBalloonHide(wParam,M.X,M.Y)
          elseif lParam == 1028 then
           TrayIcon.OnBalloonTimeOut(wParam,M.X,M.Y)
          elseif lParam == 1029 then
           TrayIcon.OnBalloonClick(wParam,M.X,M.Y)
          end
          return 0
         end
        end
        return Subclass.OldWinProc(hWnd,uMsg,wParam,lParam);
        end)
        if Subclass.HasSubclass(I) then
         TrayIcon.HostHandle = I
         return true, I
        else
         return false, "Can't set subclass"
        end
       end
      end;
       -- Icon Functions
      LoadIcon = function(sIcon,nIndex,bLarge)
       if File.DoesExist(sIcon) then
          local pIcon = MemoryEx.Allocate(4);
          if bLarge then
           nRet = 0
           while nRet <= 0 do
            nRet = Shell32Library.ExtractIconExA(sIcon,nIndex,pIcon,0,1)
           end
          else
           nRet = 0
           while nRet <= 0 do
      	  nRet = Shell32Library.ExtractIconExA(sIcon,nIndex,0,pIcon,1)
           end
          end
          local hIcon = MemoryEx.Integer(pIcon);
      	MemoryEx.Free(pIcon);
          return true, hIcon;
       else
        return false, "Icon not found"
       end
      end;
      FreeIcon = function(sIcon)
       local r = User32Library.DestroyIcon(sIcon)
       if r ~= 0 then
        return true, "OK"
       else
        return false, "Can't destroy icon"
       end
      end;
       -- Main Functions
      CreateTrayIcon = function(ID,sIcon,sTooltip)
       if not File.DoesExist(sIcon) then
        return false, "Icon not found"
       end
       if TrayIcon.HostHandle ~= 1 then
        local x,y = TrayIcon.CreateHost()
        if not x then
         return false, y
        end
       end
       local x,Ih = TrayIcon.LoadIcon(sIcon,0,false)
       if not x then
        return false, Ih
       end
       local B = MemoryEx.Allocate(MemoryEx.StructSize(NOTIFYICONDATA) + 100);
       if(B)then
        S = MemoryEx.AssignStruct(B + 50,NOTIFYICONDATA);
        if(S)then
         S.hWnd = TrayIcon.HostHandle;
         S.uID = ID;
         S.uFlags = 0x7;
         S.uCallbackMessage = 0x4DE;
         S.hIcon = Ih;
         S.szTip = sTooltip;
         S.dwState = 0;
         S.dwStateMask = 0;
         S.szInfo = 0;
         S.uTimeout = 0;
         S.uVersion = 3;
         S.szInfoTitle = 0;
         S.dwInfoFlags = 0x00000000;
         S.guidItem = 0;
         S.hBalloonIcon = 0;
         S.cbSize = 504;
        else
         MemoryEx.Free(B);
         return false, "Can't open structure"
        end
       else
        return false, "Can't create buffer"
       end
       Shell32Library.Shell_NotifyIconA(0x00000004,S:GetPointer())
       local x = tonumber(Shell32Library.Shell_NotifyIconA(0x00000000,S:GetPointer()))
       Shell32Library.Shell_NotifyIconA(0x00000004,S:GetPointer())
       MemoryEx.Free(B);
       S:Close();
       TrayIcon.FreeIcon(Ih);
       if x == 0 then
        return false, "Create tray icon failed"
       else
        return true, "OK"
       end
      end;
      DeleteTrayIcon = function(ID)
       local B = MemoryEx.Allocate(MemoryEx.StructSize(NOTIFYICONDATA) + 100);
       if(B)then
        S = MemoryEx.AssignStruct(B + 50,NOTIFYICONDATA);
        if(S)then
         S.hWnd = TrayIcon.HostHandle;
         S.uID = ID;
         S.uFlags = 0x3;
         S.uCallbackMessage = 0x4DE;
         S.hIcon = 0;
         S.szTip = 0;
         S.dwState = 0;
         S.dwStateMask = 0;
         S.szInfo = 0;
         S.uTimeout = 0;
         S.uVersion = 3;
         S.szInfoTitle = 0;
         S.dwInfoFlags = 0x00000000;
         S.guidItem = 0;
         S.hBalloonIcon = 0;
         S.cbSize = 504;
        else
         MemoryEx.Free(B);
         return false, "Can't open structure"
        end
       else
        return false, "Can't create buffer"
       end
       local x = tonumber(Shell32Library.Shell_NotifyIconA(0x00000002,S:GetPointer()))
       MemoryEx.Free(B);
       S:Close();
       if x == 0 then
        return false, "Delete tray icon failed"
       else
        return true, "OK"
       end
      end;
      ChangeTooltip = function(ID,sTooltip)
       local B = MemoryEx.Allocate(MemoryEx.StructSize(NOTIFYICONDATA) + 100);
       if(B)then
        S = MemoryEx.AssignStruct(B + 50,NOTIFYICONDATA);
        if(S)then
         S.hWnd = TrayIcon.HostHandle;
         S.uID = ID;
         S.uFlags = 0x00000004;
         S.uCallbackMessage = 0x4DE;
         S.hIcon = 0;
         S.szTip = sTooltip;
         S.dwState = 0;
         S.dwStateMask = 0;
         S.szInfo = 0;
         S.uTimeout = 0;
         S.uVersion = 3;
         S.szInfoTitle = 0;
         S.dwInfoFlags = 0x00000000;
         S.guidItem = 0;
         S.hBalloonIcon = 0;
         S.cbSize = 504;
        else
         MemoryEx.Free(B);
         return false, "Can't open structure"
        end
       else
        return false, "Can't create buffer"
       end
       local x = tonumber(Shell32Library.Shell_NotifyIconA(0x00000001,S:GetPointer()))
       MemoryEx.Free(B);
       S:Close();
       if x == 0 then
        return false, "Set tool tip failed"
       else
        return true, "OK"
       end
      end;
      ChangeIcon = function(ID,sIcon)
       if not File.DoesExist(sIcon) then
        return false, "Icon not found"
       end
       local x,Ih = TrayIcon.LoadIcon(sIcon,0,false)
       if not x then
        return false, Ih
       end
       local B = MemoryEx.Allocate(MemoryEx.StructSize(NOTIFYICONDATA) + 100);
       if(B)then
        S = MemoryEx.AssignStruct(B + 50,NOTIFYICONDATA);
        if(S)then
         S.hWnd = TrayIcon.HostHandle;
         S.uID = ID;
         S.uFlags = 0x3;
         S.uCallbackMessage = 0x4DE;
         S.hIcon = Ih;
         S.szTip = 0;
         S.dwState = 0;
         S.dwStateMask = 0;
         S.szInfo = 0;
         S.uTimeout = 0;
         S.uVersion = 3;
         S.szInfoTitle = 0;
         S.dwInfoFlags = 0x00000000;
         S.guidItem = 0;
         S.hBalloonIcon = 0;
         S.cbSize = 504;
        else
         MemoryEx.Free(B);
         return false, "Can't open structure"
        end
       else
        return false, "Can't create buffer"
       end
       local x = tonumber(Shell32Library.Shell_NotifyIconA(0x00000001,S:GetPointer()))
       MemoryEx.Free(B);
       S:Close();
       TrayIcon.FreeIcon(Ih);
       if x == 0 then
        return false, "Change icon failed"
       else
        return true, "OK"
       end
      end;
      ShowBalloon = function(ID,sTitle,sMessage,Icon,nTime,bSound,bLarge,bQuiet,bReal)
       local B = MemoryEx.Allocate(MemoryEx.StructSize(NOTIFYICONDATA) + 100);
       if(B)then
        S = MemoryEx.AssignStruct(B + 50,NOTIFYICONDATA);
        if(S)then
         TrayIcon.dwInfoFlags = Icon;
         TrayIcon.uFlags = 0x00000010;
         if bReal then
          if TrayIcon.OSName ~= "Windows XP" and TrayIcon.OSName ~= "Windows Server 2003" then
           TrayIcon.uFlags = TrayIcon.uFlags + 0x00000040;
          end
         end
         if bSound then
          TrayIcon.dwInfoFlags = TrayIcon.dwInfoFlags + 0x00000010
         end
         if bLarge then
          if TrayIcon.OSName ~= "Windows XP" and TrayIcon.OSName ~= "Windows Server 2003" then
           TrayIcon.dwInfoFlags = TrayIcon.dwInfoFlags + 0x00000020
          end
         end
         if bQuiet then
          if TrayIcon.OSName == "Windows 8.1" or TrayIcon.OSName == "Windows 8" or TrayIcon.OSName == "Windows 7" or TrayIcon.OSName == "Windows Server 2012 R2" or TrayIcon.OSName == "Windows Server 2012" then
           TrayIcon.dwInfoFlags = TrayIcon.dwInfoFlags + 0x00000080
          end
         end
         S.hWnd = TrayIcon.HostHandle;
         S.uID = ID;
         S.uFlags = TrayIcon.uFlags;
         S.uCallbackMessage = 0;
         S.hIcon = 9;
         S.szTip = 0;
         S.dwState = 0;
         S.dwStateMask = 0;
         S.szInfo = sMessage;
         S.uTimeout = nTime;
         S.uVersion = 3;
         S.szInfoTitle = sTitle;
         S.dwInfoFlags = TrayIcon.dwInfoFlags
         S.guidItem = 0;
         S.hBalloonIcon = 0;
         S.cbSize = 504;
        else
         MemoryEx.Free(B);
         return false, "Can't open structure"
        end
       else
        return false, "Can't create buffer"
       end
       local x = tonumber(Shell32Library.Shell_NotifyIconA(0x00000001,S:GetPointer()))
       MemoryEx.Free(B);
       S:Close();
       if x == 0 then
        return false, "Show balloon failed"
       else
        return true, "OK"
       end
      end;
      ShowBalloonEx = function(ID,sTitle,sMessage,Icon,nTime,bSound,bLarge,bQuiet,bReal)
       local B = MemoryEx.Allocate(MemoryEx.StructSize(NOTIFYICONDATA) + 100);
       if(B)then
        S = MemoryEx.AssignStruct(B + 50,NOTIFYICONDATA);
        if(S)then
         TrayIcon.dwInfoFlags = 0x00000004;
         TrayIcon.uFlags = 0x00000010;
         if bReal then
          if TrayIcon.OSName ~= "Windows XP" and TrayIcon.OSName ~= "Windows Server 2003" then
           TrayIcon.uFlags = TrayIcon.uFlags + 0x00000040;
          end
         end
         if bSound then
          TrayIcon.dwInfoFlags = TrayIcon.dwInfoFlags + 0x00000010
         end
         if bLarge then
          if TrayIcon.OSName ~= "Windows XP" and TrayIcon.OSName ~= "Windows Server 2003" then
           TrayIcon.dwInfoFlags = TrayIcon.dwInfoFlags + 0x00000020
          end
         end
         if bQuiet then
          if TrayIcon.OSName == "Windows 8.1" or TrayIcon.OSName == "Windows 8" or TrayIcon.OSName == "Windows 7" or TrayIcon.OSName == "Windows Server 2012 R2" or TrayIcon.OSName == "Windows Server 2012" then
           TrayIcon.dwInfoFlags = TrayIcon.dwInfoFlags + 0x00000080
          end
         end
         S.hWnd = TrayIcon.HostHandle;
         S.uID = ID;
         S.uFlags = TrayIcon.uFlags;
         S.uCallbackMessage = 0;
         S.hIcon = Icon;
         S.szTip = 0;
         S.dwState = 0;
         S.dwStateMask = 0;
         S.szInfo = sMessage;
         S.uTimeout = nTime;
         S.uVersion = 3;
         S.szInfoTitle = sTitle;
         S.dwInfoFlags = TrayIcon.dwInfoFlags
         S.guidItem = 0;
         S.hBalloonIcon = Icon;
         S.cbSize = 504;
        else
         MemoryEx.Free(B);
         return false, "Can't open structure"
        end
       else
        return false, "Can't create buffer"
       end
       local x = tonumber(Shell32Library.Shell_NotifyIconA(0x00000001,S:GetPointer()))
       MemoryEx.Free(B);
       S:Close();
       if x == 0 then
        return false, "Show balloon failed"
       else
        return true, "OK"
       end
      end;
      RemoveBalloon = function(ID)
       local B = MemoryEx.Allocate(MemoryEx.StructSize(NOTIFYICONDATA) + 100);
       if(B)then
        S = MemoryEx.AssignStruct(B + 50,NOTIFYICONDATA);
        if(S)then
         S.cbSize = 504;
         S.hWnd = TrayIcon.HostHandle;
         S.uID = ID;
         S.uFlags = 0x00000010
         S.uCallbackMessage = 0x4DE;
         S.hIcon = 0;
         S.szTip = 0;
         S.dwState = 0;
         S.dwStateMask = 0;
         S.szInfo = "";
         S.uTimeout = 0;
         S.uVersion = 3;
         S.szInfoTitle = "";
         S.dwInfoFlags = 0x00000000;
         S.guidItem = 0;
         S.hBalloonIcon = 0;
        else
         MemoryEx.Free(B);
         return false, "Can't open structure"
        end
       else
        return false, "Can't create buffer"
       end
       local x = tonumber(Shell32Library.Shell_NotifyIconA(0x00000001,S:GetPointer()))
       MemoryEx.Free(B);
       S:Close();
       if x == 0 then
        return false, "Remove balloon failed"
       else
        return true, "OK"
       end
      end;
      SetFocus = function(ID)
       local B = MemoryEx.Allocate(MemoryEx.StructSize(NOTIFYICONDATA) + 100);
       if(B)then
        S = MemoryEx.AssignStruct(B + 50,NOTIFYICONDATA);
        if(S)then
         S.hWnd = TrayIcon.HostHandle;
         S.uID = ID;
         S.uFlags = 0x00000001;
         S.uCallbackMessage = 0x4DE;
         S.hIcon = 0;
         S.szTip = 0;
         S.dwState = 0x00000001;
         S.dwStateMask = 0x00000001;
         S.szInfo = 0;
         S.uTimeout = 0;
         S.uVersion = 3;
         S.szInfoTitle = 0;
         S.dwInfoFlags = 0x00000000;
         S.guidItem = 0;
         S.hBalloonIcon = 0;
         S.cbSize = 504;
        else
         MemoryEx.Free(B)
        end
       else
        return false
       end
       local x = tonumber(Shell32Library.Shell_NotifyIconA(0x00000003,S:GetPointer()))
       MemoryEx.Free(B);
       S:Close();
       if x  == 0 then
        return false
       else
        return true
       end
      end;
       -- CallBack Functions
      OnLeftButton = function(ID,State,xPos,yPos)
       if State then
        -- Button Up
       else
        -- Button Down
       end
      end;
      OnRightButton = function(ID,State,xPos,yPos)
       if State then
        -- Button Up
       else
        -- Button Down
       end
      end;
      OnBalloonShow = function(ID,xPos,yPos)
       -- Only used if the balloon was queued
      end;
      OnBalloonHide = function(ID,xPos,yPos)
       -- The balloon has disappeared, not sent if the balloon is dismissed due to a timeout or mouse click
      end;
      OnBalloonTimeOut = function(ID,xPos,yPos)
       -- The balloon is dismissed because of a timeout
      end;
      OnBalloonClick = function(ID,xPos,yPos)
       -- The balloon is dismissed because of a mouse click
      end;
      };
      --[[
      
        http://www.memoryex.net is required.
      
        Supports:
      
         Windows 8.1
         Windows 8
         Windows 7
         Windows Vista
         Windows XP
         Windows Server 2012 R2
         Windows Server 2012
         Windows Server 2008 R2
         Windows Server 2008
         Windows Server 2003
      
         TrayIcon.ShowBalloon Function:
      
          ID = ID of the tray icon
          sTitle = Title for the balloon
          sMessage = Message for the balloon
          Icon:
      	 NIIF_NONE = No icon
      	 NIIF_INFO = Shows info icon
               NIIF_WARNING = Shows warning icon
      	 NIIF_ERROR = Shows error icon
          nTime = Timeout value in milliseconds, Windows XP & Windows Server 2003 otherwise ignored
          bSound = Do not play the associated sound. Applies only to notifications
          bLarge = The large version of the icon should be used as the notification icon, Windows Vista and later
          bQuiet = Do not display the balloon notification if the current user is in "quiet time", Windows 7 and later
          bReal = If the balloon notification cannot be displayed immediately, discard it, Windows Vista and later
      
         TrayIcon.ShowBalloonEx Function:
      
          ID = ID of the tray icon
          sTitle = Title for the balloon
          sMessage = Message for the balloon
          Icon = Handle returned from TrayIcon.LoadIcon for custom icon
          nTime = Timeout value in milliseconds, Windows XP & Windows Server 2003 otherwise ignored
          bSound = Do not play the associated sound. Applies only to notifications
          bLarge = The large version of the icon should be used as the notification icon, Windows Vista and later
          bQuiet = Do not display the balloon notification if the current user is in "quiet time", Windows 7 and later
          bReal = If the balloon notification cannot be displayed immediately, discard it, Windows Vista and later
      
        Sample Usage:
      
         -- On Show
         NICO1, y = TrayIcon.CreateTrayIcon(101,_SourceFolder.."\\Autoplay\\Icons\\1.ico","ID: 101")
         if not NICO1 then
          Dialog.Message("Error", y)
         end
      
         -- Button One Click
         if NICO1 then
          local x, y = TrayIcon.ShowBalloon(101,"Test Title","Test Message",NIIF_WARNING,0,true,false,false,true)
          if not x then
           Dialog.Message("Error", y)
          end
         end
      
         -- Button One Right Click
         if NICO1 then
          local x,Ih = TrayIcon.LoadIcon(_SourceFolder.."\\Autoplay\\Icons\\2.ico",0,true)
          if Ih then
           local x, y = TrayIcon.ShowBalloon(101,"Test Title","Test Message\nCustom Icon",Ih,0,false,true,false,false)
           if not x then
            Dialog.Message("Error", y)
           end
          else
           Dialog.Message("Error", Ih)
          end
         end
      
         -- Button Two Click
         if NICO1 then
          local x, y = TrayIcon.ChangeIcon(101,_SourceFolder.."\\Autoplay\\Icons\\2.ico")
          if not x then
           Dialog.Message("Error", y)
          end
         end
      
         -- Button Two Right Click
         if NICO1 then
          local x, y = TrayIcon.ChangeTooltip(101,"New Tooltip ID: 101")
          if not x then
           Dialog.Message("Error", y)
          end
         end
      
         -- On ShutDown
         if NICO1 then
          local x, y = TrayIcon.DeleteTrayIcon(101)
          if not x then
           Dialog.Message("Error", y)
          end
         end
      
      --]]
      This is an almost complete function set, balloons work with custom icons, balloon remove function added, just got some task-bar icon functions to add.

      Comment


      • #48
        Code:
        -- Global Functions
        Shell32Library = Library.Load("Shell32.dll");
        User32Library = Library.Load("User32.dll");
        TBPF_NOPROGRESS = 0x00000000;
        TBPF_INDETERMINATE = 0x00000001;
        TBPF_NORMAL = 0x00000002;
        TBPF_ERROR = 0x00000004;
        TBPF_PAUSED = 0x00000008;
        NIIF_NONE = 0x00000000;
        NIIF_INFO = 0x00000001;
        NIIF_WARNING = 0x00000002;
        NIIF_ERROR = 0x00000003;
        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",64,1,MEMEX_ASCII);
         DWORD "dwInfoFlags";
         GUID  "guidItem";
         HICON "hBalloonIcon";
        };
        TrayIcon = {
         -- Internal Functions
        CreateHost = function()
         TrayIcon.OSName = System.GetOSName();
         if OS == "" then
          return false, "Can't determine OS"
         end
         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 == 0x0002)then
           Subclass.Remove(I);
           return 0
          end
          if(uMsg == 0x4DE)then
           local M = System.GetMousePosition(false,nil)
           if M ~= nil then
            if lParam == 0x0201 then
             TrayIcon.OnLeftButton(wParam,false,M.X,M.Y)
            elseif lParam == 0x0202 then
             TrayIcon.OnLeftButton(wParam,true,M.X,M.Y)
            elseif lParam == 0x0204 then
             TrayIcon.OnRightButton(wParam,false,M.X,M.Y)
            elseif lParam == 0x0205 then
             TrayIcon.OnRightButton(wParam,true,M.X,M.Y)
            elseif lParam == 1024 then
             TrayIcon.OnBalloonShow(wParam,M.X,M.Y)
            elseif lParam == 1027 then
             TrayIcon.OnBalloonHide(wParam,M.X,M.Y)
            elseif lParam == 1028 then
             TrayIcon.OnBalloonTimeOut(wParam,M.X,M.Y)
            elseif lParam == 1029 then
             TrayIcon.OnBalloonClick(wParam,M.X,M.Y)
            end
            return 0
           end
          end
          return Subclass.OldWinProc(hWnd,uMsg,wParam,lParam);
          end)
          if Subclass.HasSubclass(I) then
           TrayIcon.HostHandle = I
           return true, I
          else
           return false, "Can't set subclass"
          end
         end
        end;
         -- Icon Functions
        LoadIcon = function(sIcon,nIndex,bLarge)
         if File.DoesExist(sIcon) then
            local pIcon = MemoryEx.Allocate(4);
            if bLarge then
             nRet = 0
             while nRet <= 0 do
              nRet = Shell32Library.ExtractIconExA(sIcon,nIndex,pIcon,0,1)
             end
            else
             nRet = 0
             while nRet <= 0 do
        	  nRet = Shell32Library.ExtractIconExA(sIcon,nIndex,0,pIcon,1)
             end
            end
            local hIcon = MemoryEx.Integer(pIcon);
        	MemoryEx.Free(pIcon);
            return true, hIcon;
         else
          return false, "Icon not found"
         end
        end;
        FreeIcon = function(sIcon)
         local r = User32Library.DestroyIcon(sIcon)
         if r ~= 0 then
          return true, "OK"
         else
          return false, "Can't destroy icon"
         end
        end;
         -- Main Functions
        CreateTrayIcon = function(ID,sIcon,sTooltip)
         if not File.DoesExist(sIcon) then
          return false, "Icon not found"
         end
         if TrayIcon.HostHandle ~= 1 then
          local x,y = TrayIcon.CreateHost()
          if not x then
           return false, y
          end
         end
         local x,Ih = TrayIcon.LoadIcon(sIcon,0,false)
         if not x then
          return false, Ih
         end
         local B = MemoryEx.Allocate(MemoryEx.StructSize(NOTIFYICONDATA) + 100);
         if(B)then
          S = MemoryEx.AssignStruct(B + 50,NOTIFYICONDATA);
          if(S)then
           S.hWnd = TrayIcon.HostHandle;
           S.uID = ID;
           S.uFlags = 0x7;
           S.uCallbackMessage = 0x4DE;
           S.hIcon = Ih;
           S.szTip = sTooltip;
           S.dwState = 0;
           S.dwStateMask = 0;
           S.szInfo = 0;
           S.uTimeout = 0;
           S.uVersion = 3;
           S.szInfoTitle = 0;
           S.dwInfoFlags = 0x00000000;
           S.guidItem = 0;
           S.hBalloonIcon = 0;
           S.cbSize = 504;
          else
           MemoryEx.Free(B);
           return false, "Can't open structure"
          end
         else
          return false, "Can't create buffer"
         end
         Shell32Library.Shell_NotifyIconA(0x00000004,S:GetPointer())
         local x = tonumber(Shell32Library.Shell_NotifyIconA(0x00000000,S:GetPointer()))
         Shell32Library.Shell_NotifyIconA(0x00000004,S:GetPointer())
         MemoryEx.Free(B);
         S:Close();
         TrayIcon.FreeIcon(Ih);
         if x == 0 then
          return false, "Create tray icon failed"
         else
          return true, "OK"
         end
        end;
        DeleteTrayIcon = function(ID)
         local B = MemoryEx.Allocate(MemoryEx.StructSize(NOTIFYICONDATA) + 100);
         if(B)then
          S = MemoryEx.AssignStruct(B + 50,NOTIFYICONDATA);
          if(S)then
           S.hWnd = TrayIcon.HostHandle;
           S.uID = ID;
           S.uFlags = 0x3;
           S.uCallbackMessage = 0x4DE;
           S.hIcon = 0;
           S.szTip = 0;
           S.dwState = 0;
           S.dwStateMask = 0;
           S.szInfo = 0;
           S.uTimeout = 0;
           S.uVersion = 3;
           S.szInfoTitle = 0;
           S.dwInfoFlags = 0x00000000;
           S.guidItem = 0;
           S.hBalloonIcon = 0;
           S.cbSize = 504;
          else
           MemoryEx.Free(B);
           return false, "Can't open structure"
          end
         else
          return false, "Can't create buffer"
         end
         local x = tonumber(Shell32Library.Shell_NotifyIconA(0x00000002,S:GetPointer()))
         MemoryEx.Free(B);
         S:Close();
         if x == 0 then
          return false, "Delete tray icon failed"
         else
          return true, "OK"
         end
        end;
        ChangeTooltip = function(ID,sTooltip)
         local B = MemoryEx.Allocate(MemoryEx.StructSize(NOTIFYICONDATA) + 100);
         if(B)then
          S = MemoryEx.AssignStruct(B + 50,NOTIFYICONDATA);
          if(S)then
           S.hWnd = TrayIcon.HostHandle;
           S.uID = ID;
           S.uFlags = 0x00000004;
           S.uCallbackMessage = 0x4DE;
           S.hIcon = 0;
           S.szTip = sTooltip;
           S.dwState = 0;
           S.dwStateMask = 0;
           S.szInfo = 0;
           S.uTimeout = 0;
           S.uVersion = 3;
           S.szInfoTitle = 0;
           S.dwInfoFlags = 0x00000000;
           S.guidItem = 0;
           S.hBalloonIcon = 0;
           S.cbSize = 504;
          else
           MemoryEx.Free(B);
           return false, "Can't open structure"
          end
         else
          return false, "Can't create buffer"
         end
         local x = tonumber(Shell32Library.Shell_NotifyIconA(0x00000001,S:GetPointer()))
         MemoryEx.Free(B);
         S:Close();
         if x == 0 then
          return false, "Set tool tip failed"
         else
          return true, "OK"
         end
        end;
        ChangeIcon = function(ID,sIcon)
         if not File.DoesExist(sIcon) then
          return false, "Icon not found"
         end
         local x,Ih = TrayIcon.LoadIcon(sIcon,0,false)
         if not x then
          return false, Ih
         end
         local B = MemoryEx.Allocate(MemoryEx.StructSize(NOTIFYICONDATA) + 100);
         if(B)then
          S = MemoryEx.AssignStruct(B + 50,NOTIFYICONDATA);
          if(S)then
           S.hWnd = TrayIcon.HostHandle;
           S.uID = ID;
           S.uFlags = 0x3;
           S.uCallbackMessage = 0x4DE;
           S.hIcon = Ih;
           S.szTip = 0;
           S.dwState = 0;
           S.dwStateMask = 0;
           S.szInfo = 0;
           S.uTimeout = 0;
           S.uVersion = 3;
           S.szInfoTitle = 0;
           S.dwInfoFlags = 0x00000000;
           S.guidItem = 0;
           S.hBalloonIcon = 0;
           S.cbSize = 504;
          else
           MemoryEx.Free(B);
           return false, "Can't open structure"
          end
         else
          return false, "Can't create buffer"
         end
         local x = tonumber(Shell32Library.Shell_NotifyIconA(0x00000001,S:GetPointer()))
         MemoryEx.Free(B);
         S:Close();
         TrayIcon.FreeIcon(Ih);
         if x == 0 then
          return false, "Change icon failed"
         else
          return true, "OK"
         end
        end;
        ShowBalloon = function(ID,sTitle,sMessage,Icon,nTime,bSound,bLarge,bQuiet,bReal)
         local B = MemoryEx.Allocate(MemoryEx.StructSize(NOTIFYICONDATA) + 100);
         if(B)then
          S = MemoryEx.AssignStruct(B + 50,NOTIFYICONDATA);
          if(S)then
           TrayIcon.dwInfoFlags = Icon;
           TrayIcon.uFlags = 0x00000010;
           if bReal then
            if TrayIcon.OSName ~= "Windows XP" and TrayIcon.OSName ~= "Windows Server 2003" then
             TrayIcon.uFlags = TrayIcon.uFlags + 0x00000040;
            end
           end
           if bSound then
            TrayIcon.dwInfoFlags = TrayIcon.dwInfoFlags + 0x00000010
           end
           if bLarge then
            if TrayIcon.OSName ~= "Windows XP" and TrayIcon.OSName ~= "Windows Server 2003" then
             TrayIcon.dwInfoFlags = TrayIcon.dwInfoFlags + 0x00000020
            end
           end
           if bQuiet then
            if TrayIcon.OSName == "Windows 8.1" or TrayIcon.OSName == "Windows 8" or TrayIcon.OSName == "Windows 7" or TrayIcon.OSName == "Windows Server 2012 R2" or TrayIcon.OSName == "Windows Server 2012" then
             TrayIcon.dwInfoFlags = TrayIcon.dwInfoFlags + 0x00000080
            end
           end
           S.hWnd = TrayIcon.HostHandle;
           S.uID = ID;
           S.uFlags = TrayIcon.uFlags;
           S.uCallbackMessage = 0;
           S.hIcon = 9;
           S.szTip = 0;
           S.dwState = 0;
           S.dwStateMask = 0;
           S.szInfo = sMessage;
           S.uTimeout = nTime;
           S.uVersion = 3;
           S.szInfoTitle = sTitle;
           S.dwInfoFlags = TrayIcon.dwInfoFlags
           S.guidItem = 0;
           S.hBalloonIcon = 0;
           S.cbSize = 504;
          else
           MemoryEx.Free(B);
           return false, "Can't open structure"
          end
         else
          return false, "Can't create buffer"
         end
         local x = tonumber(Shell32Library.Shell_NotifyIconA(0x00000001,S:GetPointer()))
         MemoryEx.Free(B);
         S:Close();
         if x == 0 then
          return false, "Show balloon failed"
         else
          return true, "OK"
         end
        end;
        ShowBalloonEx = function(ID,sTitle,sMessage,Icon,nTime,bSound,bLarge,bQuiet,bReal)
         local B = MemoryEx.Allocate(MemoryEx.StructSize(NOTIFYICONDATA) + 100);
         if(B)then
          S = MemoryEx.AssignStruct(B + 50,NOTIFYICONDATA);
          if(S)then
           TrayIcon.dwInfoFlags = 0x00000004;
           TrayIcon.uFlags = 0x12;
           if bReal then
            if TrayIcon.OSName ~= "Windows XP" and TrayIcon.OSName ~= "Windows Server 2003" then
             TrayIcon.uFlags = TrayIcon.uFlags + 0x00000040;
            end
           end
           if bSound then
            TrayIcon.dwInfoFlags = TrayIcon.dwInfoFlags + 0x00000010
           end
           if bLarge then
            if TrayIcon.OSName ~= "Windows XP" and TrayIcon.OSName ~= "Windows Server 2003" then
             TrayIcon.dwInfoFlags = TrayIcon.dwInfoFlags + 0x00000020
            end
           end
           if bQuiet then
            if TrayIcon.OSName == "Windows 8.1" or TrayIcon.OSName == "Windows 8" or TrayIcon.OSName == "Windows 7" or TrayIcon.OSName == "Windows Server 2012 R2" or TrayIcon.OSName == "Windows Server 2012" then
             TrayIcon.dwInfoFlags = TrayIcon.dwInfoFlags + 0x00000080
            end
           end
           S.hWnd = TrayIcon.HostHandle;
           S.uID = ID;
           S.uFlags = TrayIcon.uFlags;
           S.uCallbackMessage = 0;
           S.hIcon = Icon;
           S.szTip = 0;
           S.dwState = 0;
           S.dwStateMask = 0;
           S.szInfo = sMessage;
           S.uTimeout = nTime;
           S.uVersion = 3;
           S.szInfoTitle = sTitle;
           S.dwInfoFlags = TrayIcon.dwInfoFlags
           S.guidItem = 0;
           S.hBalloonIcon = Icon;
           S.cbSize = 504;
          else
           MemoryEx.Free(B);
           return false, "Can't open structure"
          end
         else
          return false, "Can't create buffer"
         end
         local x = tonumber(Shell32Library.Shell_NotifyIconA(0x00000001,S:GetPointer()))
         MemoryEx.Free(B);
         S:Close();
         if x == 0 then
          return false, "Show balloon failed"
         else
          return true, "OK"
         end
        end;
        RemoveBalloon = function(ID)
         local B = MemoryEx.Allocate(MemoryEx.StructSize(NOTIFYICONDATA) + 100);
         if(B)then
          S = MemoryEx.AssignStruct(B + 50,NOTIFYICONDATA);
          if(S)then
           S.cbSize = 504;
           S.hWnd = TrayIcon.HostHandle;
           S.uID = ID;
           S.uFlags = 0x00000010
           S.uCallbackMessage = 0x4DE;
           S.hIcon = 0;
           S.szTip = 0;
           S.dwState = 0;
           S.dwStateMask = 0;
           S.szInfo = "";
           S.uTimeout = 0;
           S.uVersion = 3;
           S.szInfoTitle = "";
           S.dwInfoFlags = 0x00000000;
           S.guidItem = 0;
           S.hBalloonIcon = 0;
          else
           MemoryEx.Free(B);
           return false, "Can't open structure"
          end
         else
          return false, "Can't create buffer"
         end
         local x = tonumber(Shell32Library.Shell_NotifyIconA(0x00000001,S:GetPointer()))
         MemoryEx.Free(B);
         S:Close();
         if x == 0 then
          return false, "Remove balloon failed"
         else
          return true, "OK"
         end
        end;
        SetFocus = function(ID)
         local B = MemoryEx.Allocate(MemoryEx.StructSize(NOTIFYICONDATA) + 100);
         if(B)then
          S = MemoryEx.AssignStruct(B + 50,NOTIFYICONDATA);
          if(S)then
           S.hWnd = TrayIcon.HostHandle;
           S.uID = ID;
           S.uFlags = 0x00000001;
           S.uCallbackMessage = 0x4DE;
           S.hIcon = 0;
           S.szTip = 0;
           S.dwState = 0x00000001;
           S.dwStateMask = 0x00000001;
           S.szInfo = 0;
           S.uTimeout = 0;
           S.uVersion = 3;
           S.szInfoTitle = 0;
           S.dwInfoFlags = 0x00000000;
           S.guidItem = 0;
           S.hBalloonIcon = 0;
           S.cbSize = 504;
          else
           MemoryEx.Free(B)
          end
         else
          return false
         end
         local x = tonumber(Shell32Library.Shell_NotifyIconA(0x00000003,S:GetPointer()))
         MemoryEx.Free(B);
         S:Close();
         if x  == 0 then
          return false
         else
          return true
         end
        end;
         -- CallBack Functions
        OnLeftButton = function(ID,State,xPos,yPos)
         if State then
          -- Button Up
         else
          -- Button Down
         end
        end;
        OnRightButton = function(ID,State,xPos,yPos)
         if State then
          -- Button Up
         else
          -- Button Down
         end
        end;
        OnBalloonShow = function(ID,xPos,yPos)
         -- Only used if the balloon was queued
        end;
        OnBalloonHide = function(ID,xPos,yPos)
         -- The balloon has disappeared, not sent if the balloon is dismissed due to a timeout or mouse click
        end;
        OnBalloonTimeOut = function(ID,xPos,yPos)
         -- The balloon is dismissed because of a timeout
        end;
        OnBalloonClick = function(ID,xPos,yPos)
         -- The balloon is dismissed because of a mouse click
        end;
        };
        --[[
        
          http://www.memoryex.net is required.
        
          Supports:
        
           Windows 8.1
           Windows 8
           Windows 7
           Windows Vista
           Windows XP
           Windows Server 2012 R2
           Windows Server 2012
           Windows Server 2008 R2
           Windows Server 2008
           Windows Server 2003
        
           TrayIcon.ShowBalloon Function:
        
            ID = ID of the tray icon
            sTitle = Title for the balloon
            sMessage = Message for the balloon
            Icon:
        	 NIIF_NONE = No icon
        	 NIIF_INFO = Shows info icon
                 NIIF_WARNING = Shows warning icon
        	 NIIF_ERROR = Shows error icon
            nTime = Timeout value in milliseconds, Windows XP & Windows Server 2003 otherwise ignored
            bSound = Do not play the associated sound. Applies only to notifications
            bLarge = The large version of the icon should be used as the notification icon, Windows Vista and later
            bQuiet = Do not display the balloon notification if the current user is in "quiet time", Windows 7 and later
            bReal = If the balloon notification cannot be displayed immediately, discard it, Windows Vista and later
        
           TrayIcon.ShowBalloonEx Function:
        
            ID = ID of the tray icon
            sTitle = Title for the balloon
            sMessage = Message for the balloon
            Icon = Handle returned from TrayIcon.LoadIcon for custom icon
            nTime = Timeout value in milliseconds, Windows XP & Windows Server 2003 otherwise ignored
            bSound = Do not play the associated sound. Applies only to notifications
            bLarge = The large version of the icon should be used as the notification icon, Windows Vista and later
            bQuiet = Do not display the balloon notification if the current user is in "quiet time", Windows 7 and later
            bReal = If the balloon notification cannot be displayed immediately, discard it, Windows Vista and later
        	
            TrayIcon.ShowBalloonEx replaces the tray icon and the balloon icon with the icon specified in 'Icon', to use 
            diferant icons in the tray and balloon call TrayIcon.ChangeIcon after TrayIcon.ShowBalloonEx
        
          Sample Usage:
        
           -- On Show
           NICO1, y = TrayIcon.CreateTrayIcon(101,_SourceFolder.."\\Autoplay\\Icons\\1.ico","ID: 101")
           if not NICO1 then
            Dialog.Message("Error", y)
           end
        
           -- Button One Click
           if NICO1 then
            local x, y = TrayIcon.ShowBalloon(101,"Test Title","Test Message",NIIF_WARNING,0,true,false,false,true)
            if not x then
             Dialog.Message("Error", y)
            end
           end
        
           -- Button One Right Click
           if NICO1 then
            local x,Ih = TrayIcon.LoadIcon(_SourceFolder.."\\Autoplay\\Icons\\2.ico",0,true)
            if Ih then
             local x, y = TrayIcon.ShowBalloon(101,"Test Title","Test Message\nCustom Icon",Ih,0,false,true,false,false)
             if not x then
              Dialog.Message("Error", y)
             end
            else
             Dialog.Message("Error", Ih)
            end
           end
        
           -- Button Two Click
           if NICO1 then
            local x, y = TrayIcon.ChangeIcon(101,_SourceFolder.."\\Autoplay\\Icons\\2.ico")
            if not x then
             Dialog.Message("Error", y)
            end
           end
        
           -- Button Two Right Click
           if NICO1 then
            local x, y = TrayIcon.ChangeTooltip(101,"New Tooltip ID: 101")
            if not x then
             Dialog.Message("Error", y)
            end
           end
        
           -- On ShutDown
           if NICO1 then
            local x, y = TrayIcon.DeleteTrayIcon(101)
            if not x then
             Dialog.Message("Error", y)
            end
           end
        
        --]]
        Fixed ShowBalloonEx.

        Comment


        • #49
          Code:
          -- Global Functions
          Shell32Library = Library.Load("Shell32.dll");
          User32Library = Library.Load("User32.dll");
          NIIF_NONE = 0x00000000;
          NIIF_INFO = 0x00000001;
          NIIF_WARNING = 0x00000002;
          NIIF_ERROR = 0x00000003;
          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",64,1,MEMEX_ASCII);
           DWORD "dwInfoFlags";
           GUID  "guidItem";
           HICON "hBalloonIcon";
          };
          TrayIcon = {
          SetStructure = function(x)
           if TrayIcon.StructMem == nil then
             TrayIcon.StructMem = MemoryEx.Allocate(MemoryEx.StructSize(NOTIFYICONDATA) + 100);
           end
           if TrayIcon.Structure == nil then
             TrayIcon.Structure = MemoryEx.AssignStruct(TrayIcon.StructMem + 50,NOTIFYICONDATA);
           end
           if TrayIcon.StructMem ~= nil then
            if TrayIcon.Structure ~= nil then
             TrayIcon.Structure.hWnd = TrayIcon.HostHandle;
             TrayIcon.Structure.uID = x.uID or 0;
             TrayIcon.Structure.uFlags = x.uFlags or 0;
             TrayIcon.Structure.uCallbackMessage = 0x4DE;
             TrayIcon.Structure.hIcon = x.hIcon or 0;
             TrayIcon.Structure.szTip = x.szTip or 0;
             TrayIcon.Structure.dwState = 0;
             TrayIcon.Structure.dwStateMask = 0;
             TrayIcon.Structure.szInfo = x.szInfo or 0;
             TrayIcon.Structure.uTimeout = x.uTimeout or 0;
             TrayIcon.Structure.uVersion = 3;
             TrayIcon.Structure.szInfoTitle = x.szInfoTitle or 0;
             TrayIcon.Structure.dwInfoFlags = x.dwInfoFlags or 0;
             TrayIcon.Structure.guidItem = 0;
             TrayIcon.Structure.hBalloonIcon = x.hBalloonIcon or 0;
             TrayIcon.Structure.cbSize = 504;
            else
             return false, "Can't open structure"
            end
           else
            return false, "Can't create buffer"
           end
           return true,"OK"
          end;
          CloseStructure = function()
           if TrayIcon.Structure ~= nil then
            TrayIcon.Structure:Close();
           end
           if TrayIcon.StructMem ~= nil then
            MemoryEx.Free(TrayIcon.StructMem);
           end
          end;
          CreateHost = function()
           TrayIcon.OSName = System.GetOSName();
           if OS == "" then
            return false, "Can't determine OS"
           end
           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 == 0x0002)then
             Subclass.Remove(I);
             return 0
            end
            if(uMsg == 0x4DE)then
             local M = System.GetMousePosition(false,nil)
             if M ~= nil then
              if lParam == 0x0201 then
               TrayIcon.OnLeftButton(wParam,false,M.X,M.Y)
              elseif lParam == 0x0202 then
               TrayIcon.OnLeftButton(wParam,true,M.X,M.Y)
              elseif lParam == 0x0204 then
               TrayIcon.OnRightButton(wParam,false,M.X,M.Y)
              elseif lParam == 0x0205 then
               TrayIcon.OnRightButton(wParam,true,M.X,M.Y)
              elseif lParam == 1024 then
               TrayIcon.OnBalloonShow(wParam,M.X,M.Y)
              elseif lParam == 1027 then
               TrayIcon.OnBalloonHide(wParam,M.X,M.Y)
              elseif lParam == 1028 then
               TrayIcon.OnBalloonTimeOut(wParam,M.X,M.Y)
              elseif lParam == 1029 then
               TrayIcon.OnBalloonClick(wParam,M.X,M.Y)
              end
              return 0
             end
            end
            return Subclass.OldWinProc(hWnd,uMsg,wParam,lParam);
            end)
            if Subclass.HasSubclass(I) then
             TrayIcon.HostHandle = I
             return true, I
            else
             return false, "Can't set subclass"
            end
           end
          end;
           -- Icon Functions
          LoadIcon = function(sIcon,nIndex,bLarge)
           if File.DoesExist(sIcon) then
              local pIcon = MemoryEx.Allocate(4);
              if bLarge then
               nRet = 0
               while nRet <= 0 do
                nRet = Shell32Library.ExtractIconExA(sIcon,nIndex,pIcon,0,1)
               end
              else
               nRet = 0
               while nRet <= 0 do
          	  nRet = Shell32Library.ExtractIconExA(sIcon,nIndex,0,pIcon,1)
               end
              end
              local hIcon = MemoryEx.Integer(pIcon);
              MemoryEx.Free(pIcon);
              return true, hIcon;
           else
            return false, "Icon not found"
           end
          end;
          FreeIcon = function(sIcon)
           local r = User32Library.DestroyIcon(sIcon)
           if r ~= 0 then
            return true, "OK"
           else
            return false, "Can't destroy icon"
           end
          end;
           -- Main Functions
          CreateTrayIcon = function(ID,sIcon,sTooltip)
           if TrayIcon.HostHandle ~= 1 then
            local x,y = TrayIcon.CreateHost()
            if not x then
             return false, y
            end
           end
           local x,Ih = TrayIcon.LoadIcon(sIcon,0,false)
           if not x then
            return false, Ih
           end
           local x, y = TrayIcon.SetStructure({uID=ID,uFlags=0x7,hIcon=Ih,szTip=sTooltip,dwInfoFlags=0x00000000})
           if x then
            if Shell32Library.Shell_NotifyIconA(0x00000000,TrayIcon.Structure:GetPointer()) == 0 then
             return false, "Create tray icon failed"
            else
             return true, "OK"
            end
           else
            return false, y
           end
          end;
          DeleteTrayIcon = function(ID)
           local x, y = TrayIcon.SetStructure({uID=ID,uFlags=0x3,dwInfoFlags=0x00000000})
           if x then
            if Shell32Library.Shell_NotifyIconA(0x00000002,TrayIcon.Structure:GetPointer()) == 0 then
             return false, "Delete tray icon failed"
            else
             return true, "OK"
            end
           else
            return false, y
           end
          end;
          ChangeTooltip = function(ID,sTooltip)
           local x, y = TrayIcon.SetStructure({uID=ID,uFlags=0x00000004,szTip=sTooltip,dwInfoFlags=0x00000000})
           if x then
            if Shell32Library.Shell_NotifyIconA(0x00000001,TrayIcon.Structure:GetPointer()) == 0 then
             return false, "Set tool tip failed"
            else
             return true, "OK"
            end
           else
            return false, y
           end
          end;
          ChangeIcon = function(ID,sIcon)
           if not File.DoesExist(sIcon) then
            return false, "Icon not found"
           end
           local x,Ih = TrayIcon.LoadIcon(sIcon,0,false)
           if not x then
            return false, Ih
           end
           local x, y = TrayIcon.SetStructure({uID=ID,uFlags=0x3,hIcon=Ih,dwInfoFlags=0x00000000})
           if x then
            if Shell32Library.Shell_NotifyIconA(0x00000001,TrayIcon.Structure:GetPointer()) == 0 then
             return false, "Change icon failed"
            else
             return true, "OK"
            end
           else
            return false, y
           end
          end;
          ShowBalloon = function(ID,sTitle,sMessage,Icon,nTime,bSound,bLarge,bQuiet,bReal)
             TrayIcon.dwInfoFlags = Icon;
             TrayIcon.uFlags = 0x00000010;
             if bReal then
              if TrayIcon.OSName ~= "Windows XP" and TrayIcon.OSName ~= "Windows Server 2003" then
               TrayIcon.uFlags = TrayIcon.uFlags + 0x00000040;
              end
             end
             if bSound then
              TrayIcon.dwInfoFlags = TrayIcon.dwInfoFlags + 0x00000010
             end
             if bLarge then
              if TrayIcon.OSName ~= "Windows XP" and TrayIcon.OSName ~= "Windows Server 2003" then
               TrayIcon.dwInfoFlags = TrayIcon.dwInfoFlags + 0x00000020
              end
             end
             if bQuiet then
              if TrayIcon.OSName == "Windows 8.1" or TrayIcon.OSName == "Windows 8" or TrayIcon.OSName == "Windows 7" or TrayIcon.OSName == "Windows Server 2012 R2" or TrayIcon.OSName == "Windows Server 2012" then
               TrayIcon.dwInfoFlags = TrayIcon.dwInfoFlags + 0x00000080
              end
             end
             local x, y = TrayIcon.SetStructure({uID=ID,uFlags=TrayIcon.uFlags,szInfo=sMessage,uTimeout=nTime,szInfoTitle=sTitle,dwInfoFlags=TrayIcon.dwInfoFlags})
             if x then
              if Shell32Library.Shell_NotifyIconA(0x00000001,TrayIcon.Structure:GetPointer()) == 0 then
               return false, "Show balloon failed"
              else
               return true, "OK"
              end
             else
              return false, y
             end
          end;
          ShowBalloonEx = function(ID,sTitle,sMessage,Icon,nTime,bSound,bLarge,bQuiet,bReal)
             TrayIcon.dwInfoFlags = 0x00000004;
             TrayIcon.uFlags = 0x12;
             if bReal then
              if TrayIcon.OSName ~= "Windows XP" and TrayIcon.OSName ~= "Windows Server 2003" then
               TrayIcon.uFlags = TrayIcon.uFlags + 0x00000040;
              end
             end
             if bSound then
              TrayIcon.dwInfoFlags = TrayIcon.dwInfoFlags + 0x00000010
             end
             if bLarge then
              if TrayIcon.OSName ~= "Windows XP" and TrayIcon.OSName ~= "Windows Server 2003" then
               TrayIcon.dwInfoFlags = TrayIcon.dwInfoFlags + 0x00000020
              end
             end
             if bQuiet then
              if TrayIcon.OSName == "Windows 8.1" or TrayIcon.OSName == "Windows 8" or TrayIcon.OSName == "Windows 7" or TrayIcon.OSName == "Windows Server 2012 R2" or TrayIcon.OSName == "Windows Server 2012" then
               TrayIcon.dwInfoFlags = TrayIcon.dwInfoFlags + 0x00000080
              end
             end
             local x, y = TrayIcon.SetStructure({uID=ID,uFlags=TrayIcon.uFlags,hIcon=Icon,szInfo=sMessage,uTimeout=nTime,szInfoTitle=sTitle,dwInfoFlags=TrayIcon.dwInfoFlags,hBalloonIcon=Icon})
             if x then
              if Shell32Library.Shell_NotifyIconA(0x00000001,TrayIcon.Structure:GetPointer()) == 0 then
               return false, "Show balloon failed"
              else
               return true, "OK"
              end
             else
              return false, y
             end
          end;
          RemoveBalloon = function(ID)
           local x, y = TrayIcon.SetStructure({uID=ID,uFlags=0x00000010,dwInfoFlags=0x00000000})
           if x then
            if Shell32Library.Shell_NotifyIconA(0x00000001,TrayIcon.Structure:GetPointer()) == 0 then
             return false, "Remove balloon failed"
            else
             return true, "OK"
            end
           else
            return false, y
           end
          end;
          SetFocus = function(ID)
           local x, y = TrayIcon.SetStructure({uID=ID,uFlags=0x00000001,dwInfoFlags=0x00000000})
           if x then
            if Shell32Library.Shell_NotifyIconA(0x00000003,TrayIcon.Structure:GetPointer()) == 0 then
             return false, "Can't set focus"
            else
             return true, "OK"
            end
           else
            return false, y
           end
          end;
           -- CallBack Functions
          OnLeftButton = function(ID,State,xPos,yPos)
           if State then
            -- Button Up
           else
            -- Button Down
           end
          end;
          OnRightButton = function(ID,State,xPos,yPos)
           if State then
            -- Button Up
           else
            -- Button Down
           end
          end;
          OnBalloonShow = function(ID,xPos,yPos)
           -- Only used if the balloon was queued
          end;
          OnBalloonHide = function(ID,xPos,yPos)
           -- The balloon has disappeared, not sent if the balloon is dismissed due to a timeout or mouse click
          end;
          OnBalloonTimeOut = function(ID,xPos,yPos)
           -- The balloon is dismissed because of a timeout
          end;
          OnBalloonClick = function(ID,xPos,yPos)
           -- The balloon is dismissed because of a mouse click
          end;
          };
          --[[
          
            http://www.memoryex.net is required.
          
            Supports:
          
             Windows 8.1
             Windows 8
             Windows 7
             Windows Vista
             Windows XP
             Windows Server 2012 R2
             Windows Server 2012
             Windows Server 2008 R2
             Windows Server 2008
             Windows Server 2003
          
             TrayIcon.ShowBalloon Function:
          
              ID = ID of the tray icon
              sTitle = Title for the balloon
              sMessage = Message for the balloon
              Icon:
          	 NIIF_NONE = No icon
          	 NIIF_INFO = Shows info icon
                   NIIF_WARNING = Shows warning icon
          	 NIIF_ERROR = Shows error icon
              nTime = Timeout value in milliseconds, Windows XP & Windows Server 2003 otherwise ignored
              bSound = Do not play the associated sound. Applies only to notifications
              bLarge = The large version of the icon should be used as the notification icon, Windows Vista and later
              bQuiet = Do not display the balloon notification if the current user is in "quiet time", Windows 7 and later
              bReal = If the balloon notification cannot be displayed immediately, discard it, Windows Vista and later
          
             TrayIcon.ShowBalloonEx Function:
          
              ID = ID of the tray icon
              sTitle = Title for the balloon
              sMessage = Message for the balloon
              Icon = Handle returned from TrayIcon.LoadIcon for custom icon
              nTime = Timeout value in milliseconds, Windows XP & Windows Server 2003 otherwise ignored
              bSound = Do not play the associated sound. Applies only to notifications
              bLarge = The large version of the icon should be used as the notification icon, Windows Vista and later
              bQuiet = Do not display the balloon notification if the current user is in "quiet time", Windows 7 and later
              bReal = If the balloon notification cannot be displayed immediately, discard it, Windows Vista and later
          
              TrayIcon.ShowBalloonEx replaces the tray icon and the balloon icon with the icon specified in 'Icon', to use
              diferant icons in the tray and balloon call TrayIcon.ChangeIcon after TrayIcon.ShowBalloonEx
          
            Sample Usage:
          
             -- On Show
             NICO1, y = TrayIcon.CreateTrayIcon(101,_SourceFolder.."\\Autoplay\\Icons\\1.ico","ID: 101")
             if not NICO1 then
              Dialog.Message("Error", y)
             end
          
             -- Button One Click
             if NICO1 then
              local x, y = TrayIcon.ShowBalloon(101,"Test Title","Test Message",NIIF_WARNING,0,true,false,false,true)
              if not x then
               Dialog.Message("Error", y)
              end
             end
          
             -- Button One Right Click
             if NICO1 then
              local x,Ih = TrayIcon.LoadIcon(_SourceFolder.."\\Autoplay\\Icons\\2.ico",0,true)
              if Ih then
               local x, y = TrayIcon.ShowBalloon(101,"Test Title","Test Message\nCustom Icon",Ih,0,false,true,false,false)
               if not x then
                Dialog.Message("Error", y)
               end
              else
               Dialog.Message("Error", Ih)
              end
             end
          
             -- Button Two Click
             if NICO1 then
              local x, y = TrayIcon.ChangeIcon(101,_SourceFolder.."\\Autoplay\\Icons\\2.ico")
              if not x then
               Dialog.Message("Error", y)
              end
             end
          
             -- Button Two Right Click
             if NICO1 then
              local x, y = TrayIcon.ChangeTooltip(101,"New Tooltip ID: 101")
              if not x then
               Dialog.Message("Error", y)
              end
             end
          
             -- On ShutDown
             if NICO1 then
              local x, y = TrayIcon.DeleteTrayIcon(101)
              if not x then
               Dialog.Message("Error", y)
              end
             end
             TrayIcon.CloseStructure()
          
          --]]
          200 lines less code and a bit faster.

          Comment


          • #50


            Changed it so functions with icons accept strings or handles.

            Comment


            • #51
              Originally posted by Shrek View Post
              http://pastebin.com/igs7LnCn

              Changed it so functions with icons accept strings or handles.
              You have worked hard on this so far man, well do, wish I could of had more input and tried it out more but even now I can't as can't access paistbin and my internet is bad and I just moved house so rare I get to sit down lol

              Keep up the good work Shrek its nice to see you still posting this even tho you don't get many reply's my hat go's off two you and I hope to do the same in the future
              Plugins or Sources MokoX
              BunnyHop Here

              Comment


              • #52
                +1 said king

                Comment

                Working...
                X