Announcement

Collapse
No announcement yet.

Notification Icon

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

  • #31
    I'm loving this thread, good work y'all!
    Bas Groothedde
    Imagine Programming :: Blog

    AMS8 Plugins
    IMXLH Compiler

    Comment


    • #32
      In the MS docs it says you can just define part structures but I can't get it to work without listing the full structure each time.
      you can but you need to add padding, best to just define the whole structure

      ^^cheers, heres a bit of an update:
      nice work :yes

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



      Shrek, how far you going to take this??, are you going to incorporate any taskbar functionally, progress bar, buttons, jump lists etc???

      i remember someone started such a project and i gave some help there but from what i remember it seemed dead in the water???
      Embrace change in your life, you never know, it could all work out for the best

      Comment


      • #33
        I was looking to do all the tray and task bar functionality, this guy here has a public dll for most of the functions and I'm sure its compatible with AMS/MemoryEx but there are no arguments or anything supplied:



        not sure how to do it direct with MemoryEx as its using the ITaskbarList but
        Explorerframe.dll has only one function in it:

        Comment


        • #34
          Well I going to keep following this and also testing over hear for you all I can really do but I guess testing is a means of helping hehe.

          Did you also download the dlls doc file? it might have how to use it there also using a dll version might help you see the functions also.
          Plugins or Sources MokoX
          BunnyHop Here

          Comment


          • #35
            its a Visual Fox Pro class, cant find any dll decs in the source code, not sure if it can be used iv never touched anything to do with VFP!

            i thought VPF was like Visual Basic, controls, active x and such

            i did this a while back in PureBasic, only thing i did not add was the jump list, i'll see if i can find that source

            EDIT: found my old post, lol

            Embrace change in your life, you never know, it could all work out for the best

            Comment


            • #36
              Code:
              ---Global MemoryEx plugin needed
              WM_USER = 0x0400;
              LR_LOADFROMFILE = 0x0010;
              LR_SHARED = 0x00008000;
              LR_DEFAULTSIZE = 0x00000040;
              IMAGE_ICON = 1;
              DI_NORMAL = 0x0003;
              NIF_MESSAGE = 0x00000001;
              NIF_ICON = 0x00000002;
              NIF_TIP = 0x00000004;
              NIF_STATE = 0x00000008;
              NIF_INFO = 0x00000010;
              NIF_GUID = 0x00000020;
              NIF_REALTIME = 0x00000040;
              NIF_SHOWTIP = 0x00000080;
              NOTIFYICONDATA_V1_SIZE = 88;
              NOTIFYICONDATA_V2_SIZE = 488;
              NOTIFYICONDATA_V3_SIZE = 504;
              NOTIFYICONDATA_V4_SIZE = 508;
              NIIF_NONE = 0x00000000;
              NIIF_INFO = 0x00000001;
              NIIF_WARNING = 0x00000002;
              NIIF_ERROR = 0x00000003;
              NIIF_USER = 0x00000004;
              NIIF_NOSOUND = 0x00000010;
              NIIF_LARGE_ICON = 0x00000020;
              NIIF_RESPECT_QUIET_TIME = 0x00000080;
              NIIF_ICON_MASK = 0x0000000F;
              NIS_HIDDEN = 0x00000001;
              NIS_SHAREDICON = 0x00000002;
              NOTIFYICON_VERSION = 3;
              NOTIFYICON_VERSION_4 = 4;
              NIM_ADD = 0x00000000;
              NIM_DELETE = 0x00000002;
              NIM_MODIFY = 0x00000001;
              HWND_MESSAGE = -3;
              WM_LBUTTONDOWN = 0x0201;
              WM_LBUTTONUP = 0x0202;
              WM_RBUTTONDOWN = 0x0204;
              WM_RBUTTONUP = 0x0205;
              WM_CONTEXTMENU = 0x007B;
              TC_CBACK = WM_USER + 222;
              
              Shell32Library = Library.Load("Shell32.dll");
              User32Library = Library.Load("user32.dll");
              
              PTR = INT;
              LONG = INT;
              HWND = INT;
              HICON = INT;
              TCHAR = STRING;
              GUID = INT;
              NOTIFYICONDATA = MemoryEx.DefineStruct{
                DWORD "cbSize";
                HWND  "hWnd";
                UINT  "uID";
                UINT  "uFlags";
                UINT  "uCallbackMessage";
                HICON "hIcon";
                TCHAR ("szTip",128,1,MEMEX_ASCII);
                DWORD "dwState";
                DWORD "dwStateMask";
                TCHAR ("szInfo",256,1,MEMEX_ASCII);
                UNION {
                  UINT "uTimeout";
                  UINT "uVersion";
                };
                TCHAR ("szInfoTitle",256,1,MEMEX_ASCII);
                DWORD "dwInfoFlags";
                GUID  "guidItem";
                HICON "hBalloonIcon";
              };
              
              Tray = {}
              
              Tray.FreeIcon = function(sIcon)
                local hIcon = User32Library.DestroyIcon(sIcon)
                if hIcon ~= 0 then
                 return true, "OK"
                else
                 return false, "Can't destroy icon"
                end
              end;
              
              Tray.LoadIcon = function(sIcon)
                local hIcon = User32Library.LoadImageA(0,sIcon,IMAGE_ICON,0,0,LR_LOADFROMFILE)
                if (hIcon ~= nil and hIcon > 0) then
                 return true, hIcon
                else
                 return false, "Can't load icon"
                end
              end;
              
              Tray.DllVersionInfo = function()
               local OS = System.GetOSName();
               if OS == "" then
                return false, "Can't determine OS"
               end
               if OS == "Windows XP" or OS == "Windows Server 2003" then
                Tray.MainStructSize = NOTIFYICON_VERSION
               end
               Tray.OSName = OS
               Tray.VersionSet = 1
               return true, "OK"
              end;
              
              Tray.CreateTrayIcon = function(iID,sIcon,sTool)
               if Tray.VersionSet ~= 1 then
                local x,y = Tray.DllVersionInfo()
                if not x then
                 return false, y
                end
               end
               local x,Ih = Tray.LoadIcon(sIcon)
               if not x then
                return false, Ih
               end
               local lpBuff = MemoryEx.Allocate(MemoryEx.StructSize(NOTIFYICONDATA) + 100);
               if(lpBuff)then
                hStruct = MemoryEx.AssignStruct(lpBuff + 50,NOTIFYICONDATA);
                if(hStruct)then
                 hStruct.hWnd = Application.GetWndHandle();
                 hStruct.uID = iID;
                 hStruct.uFlags = NIF_MESSAGE + NIF_ICON + NIF_TIP;
                 hStruct.uCallbackMessage = TC_CBACK; 
                 hStruct.hIcon = Ih;
                 hStruct.szTip = sTool;
                 hStruct.dwState = NIS_HIDDEN;
                 hStruct.dwStateMask = NIS_HIDDEN;
                 hStruct.szInfo = "";
                 hStruct.uTimeout = 0;
                 hStruct.uVersion = NOTIFYICON_VERSION;
                 hStruct.szInfoTitle = "";
                 hStruct.dwInfoFlags = NIIF_NONE;
                 hStruct.guidItem = 0;
                 hStruct.hBalloonIcon = "";	
                 hStruct.cbSize = Tray.MainStructSize or hStruct:Size();
                else
                 MemoryEx.Free(lpBuff);
                 return false, "Can't open structure"
                end
               else
                return false, "Can't create buffer"
               end
               local poi = hStruct:GetPointer();	 
               if tonumber(Shell32Library.Shell_NotifyIcon(NIM_ADD,poi)) == 0 then
                MemoryEx.Free(lpBuff);
                hStruct:Close();
                Tray.FreeIcon(Ih);
                return false, "Create tray icon failed"
               else
                MemoryEx.Free(lpBuff);
                hStruct:Close();  
                Tray.FreeIcon(Ih);
                return true, "OK"
               end
              end;
              
              Tray.SetToolTip = function(iID,tip)
               local lpBuff = MemoryEx.Allocate(MemoryEx.StructSize(NOTIFYICONDATA) + 100);
               if(lpBuff)then
                hStruct = MemoryEx.AssignStruct(lpBuff + 50,NOTIFYICONDATA);
                if(hStruct)then
                 hStruct.hWnd = Application.GetWndHandle();
                 hStruct.uID = iID;
                 hStruct.uFlags = NIF_TIP;
                 hStruct.uCallbackMessage = TC_CBACK; 
                 hStruct.hIcon = Ih;
                 hStruct.szTip = tip;
                 hStruct.dwState = NIS_HIDDEN;
                 hStruct.dwStateMask = NIS_HIDDEN;
                 hStruct.szInfo = "";
                 hStruct.uTimeout = 0;
                 hStruct.uVersion = NOTIFYICON_VERSION;
                 hStruct.szInfoTitle = "";
                 hStruct.dwInfoFlags = NIIF_NONE;
                 hStruct.guidItem = 0;
                 hStruct.hBalloonIcon = "";	
                 hStruct.cbSize = Tray.MainStructSize or hStruct:Size();
                else
                 MemoryEx.Free(lpBuff);
                 return false, "Can't open structure"
                end
               else
                return false, "Can't create buffer"
               end
               local poi = hStruct:GetPointer();	 
               if tonumber(Shell32Library.Shell_NotifyIcon(NIM_MODIFY,poi)) == 0 then
                MemoryEx.Free(lpBuff);
                hStruct:Close();
                return false, "Set tool tip failed"
               else
                MemoryEx.Free(lpBuff);
                hStruct:Close();
                return true, "OK"
               end
              end;
              
              Tray.ShowBalloon = function(iID,nTimeout,sTitle,sMessage,bNosound,bLargeIcon,Icon,bQuiet)
               local lpBuff = MemoryEx.Allocate(MemoryEx.StructSize(NOTIFYICONDATA) + 100);
               if(lpBuff)then
                hStruct = MemoryEx.AssignStruct(lpBuff + 50,NOTIFYICONDATA);
                if(hStruct)then
                 hStruct.hWnd = Application.GetWndHandle();
                 hStruct.uID = iID;
                 hStruct.uFlags =  NIF_MESSAGE + NIF_INFO;
                 hStruct.uCallbackMessage = TC_CBACK; 
                 hStruct.hIcon = Ih;
                 hStruct.szTip = sTool;
                 hStruct.dwState = NIS_HIDDEN;
                 hStruct.dwStateMask = NIS_HIDDEN;
                 hStruct.szInfo = sMessage;
                 hStruct.uTimeout = nTimeout;
                 hStruct.uVersion = NOTIFYICON_VERSION;
                 hStruct.szInfoTitle = sTitle;
                 local Iflags = Icon;
                 if bNosound then
                  if Tray.OSName ~= "Windows 2000" then
                   Iflags = Iflags + NIIF_NOSOUND;
              	end
                 end
                 if bLargeIcon then
                  if Tray.OSName == "Windows 8" or Tray.OSName == "Windows Server 2012" or Tray.OSName == "Windows 7" or Tray.OSName == "Windows Server 2008 R2" or Tray.OSName == "Windows Vista" or Tray.OSName == "Windows Server 2008" then
                   Iflags = Iflags + NIIF_LARGE_ICON;
                  end
                 end
                 if bQuiet then
                  if Tray.OSName == "Windows 8" or Tray.OSName == "Windows Server 2012" or Tray.OSName == "Windows 7" then
                   Iflags = Iflags + NIIF_RESPECT_QUIET_TIME;
                  end   
                 end
                 hStruct.dwInfoFlags = Iflags;
                 hStruct.guidItem = 0;
                 hStruct.hBalloonIcon = "";	
                 hStruct.cbSize = Tray.MainStructSize or hStruct:Size();
                else
                 MemoryEx.Free(lpBuff);
                 return false, "Can't open structure"
                end
               else
                return false, "Can't create buffer"
               end
               local poi = hStruct:GetPointer();	 
               if tonumber(Shell32Library.Shell_NotifyIcon(NIM_MODIFY,poi)) == 0 then
                MemoryEx.Free(lpBuff);
                hStruct:Close();
                return false, "Set balloon failed"
               else
                MemoryEx.Free(lpBuff);
                hStruct:Close();
                return true, "OK"
               end
              end;
              
              Tray.DeleteTrayIcon = function(iID)
               local lpBuff = MemoryEx.Allocate(MemoryEx.StructSize(NOTIFYICONDATA) + 100);
               if(lpBuff)then
                hStruct = MemoryEx.AssignStruct(lpBuff + 50,NOTIFYICONDATA);
                if(hStruct)then
                 hStruct.hWnd = Application.GetWndHandle();
                 hStruct.uID = iID;
                 hStruct.uFlags = NIF_MESSAGE + NIF_ICON;
                 hStruct.uCallbackMessage = TC_CBACK; 
                 hStruct.hIcon = Ih;
                 hStruct.szTip = "";
                 hStruct.dwState = NIS_HIDDEN;
                 hStruct.dwStateMask = NIS_HIDDEN;
                 hStruct.szInfo = "";
                 hStruct.uTimeout = 0;
                 hStruct.uVersion = NOTIFYICON_VERSION;
                 hStruct.szInfoTitle = "";
                 hStruct.dwInfoFlags = NIIF_NONE;
                 hStruct.guidItem = 0;
                 hStruct.hBalloonIcon = "";	
                 hStruct.cbSize = Tray.MainStructSize or hStruct:Size();
                else
                 MemoryEx.Free(lpBuff);
                 return false, "Can't open structure"
                end
               else
                return false, "Can't create buffer"
               end
               local poi = hStruct:GetPointer();	 
               if tonumber(Shell32Library.Shell_NotifyIcon(NIM_DELETE,poi)) == 0 then
                MemoryEx.Free(lpBuff);
                hStruct:Close();
                return false, "Delete tray icon failed"
               else
                MemoryEx.Free(lpBuff);
                hStruct:Close();
                return true, "OK"
               end
              end;
              
              Tray.ChangeIcon = function(iID,sIcon)
               local x,Ih = Tray.LoadIcon(sIcon)
               if not x then
                return false, Ih
               end
               local lpBuff = MemoryEx.Allocate(MemoryEx.StructSize(NOTIFYICONDATA) + 100);
               if(lpBuff)then
                hStruct = MemoryEx.AssignStruct(lpBuff + 50,NOTIFYICONDATA);
                if(hStruct)then
                 hStruct.hWnd = Application.GetWndHandle();
                 hStruct.uID = iID;
                 hStruct.uFlags = NIF_MESSAGE + NIF_ICON;
                 hStruct.uCallbackMessage = TC_CBACK; 
                 hStruct.hIcon = Ih;
                 hStruct.szTip = tip;
                 hStruct.dwState = NIS_HIDDEN;
                 hStruct.dwStateMask = NIS_HIDDEN;
                 hStruct.szInfo = "";
                 hStruct.uTimeout = 0;
                 hStruct.uVersion = NOTIFYICON_VERSION;
                 hStruct.szInfoTitle = "";
                 hStruct.dwInfoFlags = NIIF_NONE;
                 hStruct.guidItem = 0;
                 hStruct.hBalloonIcon = "";	
                 hStruct.cbSize = Tray.MainStructSize or hStruct:Size();
                else
                 MemoryEx.Free(lpBuff);
                 return false, "Can't open structure"
                end
               else
                return false, "Can't create buffer"
               end
               local poi = hStruct:GetPointer();	 
               if tonumber(Shell32Library.Shell_NotifyIcon(NIM_MODIFY,poi)) == 0 then
                MemoryEx.Free(lpBuff);
                hStruct:Close();
                Tray.FreeIcon(Ih);
                return false, "Change icon failed"
               else
                MemoryEx.Free(lpBuff);
                hStruct:Close();
                Tray.FreeIcon(Ih);
                return true, "OK"
               end
              end;
              
              Tray.Callback = function (hwnd,umsg,wParam,lParam)
               if lParam == WM_LBUTTONDOWN then
                Debug.Print("WM_LBUTTONDOWN("..wParam..")\r\n");	
               elseif lParam == WM_LBUTTONUP then
                Debug.Print("WM_LBUTTONUP("..wParam..")\r\n");	
               elseif lParam == WM_RBUTTONDOWN then
                Debug.Print("WM_RBUTTONDOWN("..wParam..")\r\n");
               elseif lParam == WM_RBUTTONUP then
                Debug.Print("WM_RBUTTONUP("..wParam..")\r\n");		
               end
              end;
              
              -- On Show
              
              --Debug.ShowWindow();
              local s = Subclass.Create(Application.GetWndHandle(), function(hWnd,uMsg,wParam,lParam)
               if(uMsg == TC_CBACK)then
                Tray.Callback(hwnd,umsg,wParam,lParam)
                return 0;
               end
               return Subclass.OldWinProc(hWnd,uMsg,wParam,lParam);
              end)
              local x,err = Tray.CreateTrayIcon(101,_SourceFolder.."\\Autoplay\\Icons\\1.ico","Notification Icon 1")
              if not x then
               Dialog.Message("",err)
              end
              
              --On Close
              
              Tray.DeleteTrayIcon(101)
              Subclass.Remove(Application.GetWndHandle())
              
              --[[
              
                 Show Ballon Example
              
              -- Tray ID
              -- Timeout, works with Win 200/XP only otherwise ignored
              -- Title, max 48 character max
              -- Message, 200 character max
              -- No sound, Ignored on win 2000
              -- Large icon, ignored on win 2000/XP
              -- Stock Icon = NIIF_NONE  NIIF_INFO  NIIF_WARNING  NIIF_ERROR
              -- Respect quiet time, Win 7/8 ignored otherwise
              
              local x, y = Tray.ShowBalloon(101,0,"","Test Message\r\nMulti Line",false,false,NIIF_WARNING,false)
              if not x then
               Dialog.Message("",y)
              end
              
              --]]
              Can't seem to get a balloon to show though it reports as having done so..........

              Comment


              • #37
                just an FYI on removing the subclass, catch the WM_CLOSE message and remove it from there (also do any other clean up's from here), that way your users don't have to worry about it and it leaves you free to offer user defined functions for the events without getting them into the detail of subclassing as the point of a plugin is to simplify things

                Code:
                WM_CLOSE = 0x0010;
                function MyCallback(hWnd, uMsg, wParam, lParam)
                	
                	-- must be called before "Subclass.Remove"
                	Subclass.OldWinProc(hWnd, uMsg, wParam, lParam);
                	
                	-- if the window closes
                	if (uMsg == WM_CLOSE) then
                		-- The subclass will now be removed!
                		Subclass.Remove(hWnd);
                	end
                end
                Subclass.Create(Application.GetWndHandle(), MyCallback);
                i will look at your script when i got my nipper in bed, from what i remember the ballon was a real (female dog) to get working in PB :yes

                EDIT: on second thoughts, your better off catching the WM_DESTROY message in case the system closes the window
                WM_DESTROY = 0x0002;
                (still a little rusty, its all flooding back tho, lol~)
                Embrace change in your life, you never know, it could all work out for the best

                Comment


                • #38
                  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

                  Comment


                  • #39
                    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. ^^
                    Bas Groothedde
                    Imagine Programming :: Blog

                    AMS8 Plugins
                    IMXLH Compiler

                    Comment


                    • #40
                      I shall add it to the WM_DESTROY message, cheers guys :yes

                      Comment


                      • #41
                        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
                        
                        --]]

                        Comment


                        • #42
                          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!
                          Embrace change in your life, you never know, it could all work out for the best

                          Comment


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

                            Comment


                            • #44
                              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.

                              Comment


                              • #45
                                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?

                                Comment

                                Working...
                                X