Announcement

Collapse
No announcement yet.

Notification Icon

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

  • naxo
    replied
    +1 said king

    Leave a comment:


  • kingzooly
    replied
    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

    Leave a comment:


  • Shrek
    replied


    Changed it so functions with icons accept strings or handles.

    Leave a comment:


  • Shrek
    replied
    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.

    Leave a comment:


  • Shrek
    replied
    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.

    Leave a comment:


  • Shrek
    replied
    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.

    Leave a comment:


  • Shrek
    replied
    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...................

    Leave a comment:


  • Shrek
    replied
    Code:
    --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
    --]]
    So the balloons now work along with the balloon on click event but the balloons wont show icons, they should be able to show the predefined icons:

    Code:
    NIIF_NONE = 0x00000000;
    NIIF_INFO = 0x00000001;
    NIIF_WARNING = 0x00000002;
    NIIF_ERROR = 0x00000003;
    or using:

    Code:
    NIIF_USER = 0x00000004;
    a custom icon but whatever icon is used should be able to be shown standard size or large but in any event none will show so anyone know whats up?

    Leave a comment:


  • Shrek
    replied
    Code:
    --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
    --]]
    So back playing with this and I still can't for the life of me get a balloon to show, can't get balloons in general to show nor tooltips actually and the methods are all very similar so it might be the same oversight, I have tried every conceivable option and it always reports as having worked but it never does.

    The above code has the simplest form of balloon notification with no icon to show and it follows the guidelines but nothing happens, the balloon wont show at all if there is no text passed in szInfo and szInfo differs slightly in the structure as it takes text rather than a pointer to a buffer but the szTip does the same and it works just fine on creating a tray icon and on changing the tooltip text.

    Leave a comment:


  • Shrek
    replied
    Hi RizlaUK, sorry about your pain but thank you so much for your time, I learned a lot :yes

    Leave a comment:


  • RizlaUK
    replied
    i always remove my subclasses when the window or object gets destroyed, its good practice to always clean up your app memory and callback settings upon exit coz once you get a memory leak it can take weeks/months to track down if at all sometimes

    sorry i cant be much help with the balloon right now, i had a small operation last week on my jaw and the pain has really flared up the last couple of days i just cant concentrate!

    Leave a comment:


  • Shrek
    replied
    Code:
    ---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
    
    --]]

    Leave a comment:


  • Shrek
    replied
    I shall add it to the WM_DESTROY message, cheers guys :yes

    Leave a comment:


  • Imagine Programming
    replied
    It's wise to always remove the subclass Shrek, even if you are sure MemoryEx will handle it on
    the moment the window gets destroyed. ^^

    Leave a comment:


  • Shrek
    replied
    Cheers mate, you know I got it sub-classed in a host window OK so no need to remove the subclass as its only main windows that need that:

    Code:
    ---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
    
    --]]
    Its literally just the balloon to show then one more load icon function for custom balloon icons then a bit of error checking to go :lol

    Leave a comment:

Working...
X