Announcement

Collapse
No announcement yet.

Notification Icon

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

  • #16
    Code:
     
    	if tonumber(Shell32Library.Shell_NotifyIcon(NIM_ADD,poi)) == 0 then
    		MemoryEx.Free(lpBuff);
    		hStruct:Close();
    		TTIi.DestroyIcon(Ih)
    		return false, "Create tray icon failed"
    	else
    		MemoryEx.Free(lpBuff);
    		hStruct:Close();          
    		TTIi.DestroyIcon(Ih)
    		return true, "OK"
    	end
    Could Be

    Code:
    	MemoryEx.Free(lpBuff);
    	hStruct:Close();          
    	TTIi.DestroyIcon(Ih);
    	if tonumber(Shell32Library.Shell_NotifyIcon(NIM_ADD,poi)) == 0 then
    		return false, "Create tray icon failed"
    	else
    		return true, "OK"
    	end
    Plugins or Sources MokoX
    BunnyHop Here

    Comment


    • #17
      Rex, what i did

      look on lines 79, 110, 114, 118, 132, 190, 194, 235

      Code:
      ---Global MemoryEx plugin needed
      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";
      };
              TTIi = {
                  DllVersionInfo = function()
                   local OS = System.GetOSName();
                   if OS == "" then
                    return false, "Can't determine OS"
                   end
                   if OS == "Windows 8" or OS == "Windows Server 2012" or OS == "Windows 7" or OS == "Windows Server 2008 R2" or OS == "Windows Vista" or OS == "Windows Server 2008" then
                    local size = MemoryEx.StructSize(NOTIFYICONDATA)
                    if not size then
                     return false, "Can't get structure size"
                    end
                    TTIi.UVERS = NOTIFYICON_VERSION_4
                    TTIi.MainStructSize = size
                    if OS == "Windows 8" or OS == "Windows Server 2012" or OS == "Windows 7" or OS == "Windows Server 2008 R2" then
                     TTIi.GUID = 0
                    else
                     TTIi.GUID = 0
                    end
                    TTIi.VersionSet = 1
                    return true, "OK"
                   end
                   if OS == "Windows XP" or OS == "Windows Server 2003" then
                    TTIi.UVERS = NOTIFYICON_VERSION_4
                    TTIi.MainStructSize = NOTIFYICON_VERSION
                    TTIi.VersionSet = 1
                    TTIi.GUID = 0
                    return true, "OK"
                   else
                    return false, "OS not supported"
                   end
                  end;
                  GetStrucPointer = function(str)
                   local lpBuff = MemoryEx.Allocate(MemoryEx.StructSize(str) + 100);
                   if(lpBuff)then
                    local hStruct = MemoryEx.AssignStruct(lpBuff + 50,str);
                    if(hStruct)then
                     local lpStruct = hStruct:GetPointer();
                     MemoryEx.Free(lpBuff);
                     hStruct:Close();
                     return true, lpStruct
                    else
                     MemoryEx.Free(lpBuff);
                     return false, "Can't open structure (Pointer)"
                    end
                   else
                    return false, "Can't create buffer (Pointer)"
                   end
                  end;
                  InitiliseCallbBack = function()
                    --local bhdlr = User32Library.CreateWindowExA(0,"EDIT","",0,0,0,0,0,HWND_MESSAGE,0,0,0)
                     bhdlr = User32Library.CreateWindowExA(0,"Message","",0,0,0,0,0,HWND_MESSAGE,0,0,0)
                    if bhdlr and (type(bhdlr) ~= "number") then
                     return false, "Can't create button handler"
                    elseif bhdlr == 0 then
                     return false, "Can't create button handler"
                    else
                     TTIi.CallBackSet = 1
                     TTIi.CallBackHDL = I
                     return true, bhdlr
                    end
                  end;
                  DestroyIcon = function(sIcon)
                    local hIcon = User32Library.DestroyIcon(sIcon)
                    if hIcon ~= 0 then
                     return true, "OK"
                    else
                     return false, "Can't destroy icon"
                    end
                   end;
                  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;
                  SetStructureCreate = function(Icon,Tip)
                   local lpBuff = MemoryEx.Allocate(MemoryEx.StructSize(NOTIFYICONDATA) + 100);
                   if(lpBuff)then
                    --local hStruct = MemoryEx.AssignStruct(lpBuff + 50,NOTIFYICONDATA);
                    hStruct = MemoryEx.AssignStruct(lpBuff + 50,NOTIFYICONDATA);
                    if(hStruct)then
                     hStruct.cbSize = TTIi.MainStructSize;
                     --hStruct.hWnd = TTIi.CallBackHDL;
                     hStruct.hWnd = bhdlr;
                     hStruct.uID = 100;
                     hStruct.uFlags = NIF_MESSAGE + NIF_ICON + NIF_TIP;
                     --hStruct.uCallbackMessage = 101;
                     hStruct.uCallbackMessage = TTIi.CallBackHDL;
                     hStruct.hIcon = Icon;
                     hStruct.szTip = Tip;
                     hStruct.dwState = NIS_HIDDEN;
                     hStruct.dwStateMask = NIS_HIDDEN;
                     hStruct.szInfo = "";
                     hStruct.uTimeout = 0;
                     hStruct.uVersion = TTIi.UVERS
                     hStruct.szInfoTitle = "";
                     hStruct.dwInfoFlags = NIIF_NONE;
                     hStruct.guidItem = TTIi.GUID;
                     hStruct.hBalloonIcon = "";
                     MemoryEx.Free(lpBuff);
                     --hStruct:Close();
                     return true, "OK"
                    else
                     MemoryEx.Free(lpBuff);
                     return false, "Can't open structure (Set)"
                    end
                   else
                    return false, "Can't create buffer (Set)"
                   end
                  end;
      			CheckFunction = function(sIcon,sTool)
                   if not sIcon then
                    return false, "No icon path supplied"
                   end
                   if not sTool then
                    return false, "No tooltip supplied"
                   end
                   if sTool and (type(sTool) ~= "string") then
                    return false, "Tooltip is not a string"
                   end
                   if String.Length(sTool) > 128 then
                    return false, "Tooltip lenth can only be a maximum of 128 characters"
                   end
                   if sIcon and (type(sIcon) ~= "string") then
                    return false, "Icon path is not a string"
                   end
                   if not File.DoesExist(sIcon) then
                    return false, "Icon not found: "..sIcon
                   end
                   return true, "OK"
      			end;
      			};
              TTI = {
                  CreateTrayIcon = function(sIcon,sTool)
                   local x,y = TTIi.CheckFunction(sIcon,sTool)
                   if not x then
                    return false, y
                   end
      			 if TTIi.VersionSet ~= 1 then
                    local x,y = TTIi.DllVersionInfo()
                    if not x then
                     return false, y
                    end
                   end
      			 if TTIi.CallBackSet ~= 1 then
                    local x,cHdl = TTIi.InitiliseCallbBack()
                    if not x then
                     return false, cHdl
                    end
      			 end
      			 local x,Ih = TTIi.LoadIcon(sIcon)
                   if not x then
                    return false, Ih
                   end
                   local x, y = TTIi.SetStructureCreate(Ih,sTool)
                   if not x then
                    return false, y
                   end
                   --local x, poi = TTIi.GetStrucPointer(NOTIFYICONDATA)
                   --if not x then
                   -- return false, poi
                   --end
                   if tonumber(Shell32Library.Shell_NotifyIcon(NIM_ADD,hStruct:GetPointer())) == 0 then
                    TTIi.DestroyIcon(Ih)
                    hStruct:Close()
                    return false, "Create tray icon failed"
                   else
                    TTIi.DestroyIcon(Ih)
                    return true, "OK"
                   end
                  end;
              };
              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;
      		--HWND_MESSAGE = -3;
      		HWND_MESSAGE = Application.GetWndHandle();
      -- Button On Click
      local x,err = TTI.CreateTrayIcon(_SourceFolder.."\\AutoPlay\\Icons\\cdpencil.ico","Notification Icon")
      if not x then
       Dialog.Message("",err)
      end
      EDIT: had a glitch in there, try now
      Last edited by RizlaUK; 09-16-2013, 04:52 PM. Reason: ERRORS
      Embrace change in your life, you never know, it could all work out for the best

      Comment


      • #18
        Line 195, and 199 don't need to be called twice it could be called on 193 TTIi.DestroyIcon(Ih); just the once


        Also you version I get this error Riz:
        ---------------------------
        Can't create button handler
        ---------------------------
        OK

        Code:
        InitiliseCallbBack = function()
        	--local bhdlr = User32Library.CreateWindowExA(0,"EDIT","",0,0,0,0,0,HWND_MESSAGE,0,0,0)
        	bhdlr = User32Library.CreateWindowExA(0,"Message","",0,0,0,0,0,HWND_MESSAGE,0,0,0)
        	if bhdlr and (type(bhdlr) ~= "number") then
        		return false, "Can't create button handler (Not Number)"
        	elseif bhdlr == 0 then
        		return false, "Can't create button handler"
        	else
        		TTIi.CallBackSet = 1
        		TTIi.CallBackHDL = I
        		return true, bhdlr
        	end
        end;
        Looks like bhdlr is returning 0
        Last edited by kingzooly; 09-16-2013, 05:04 PM. Reason: Adding more details
        Plugins or Sources MokoX
        BunnyHop Here

        Comment


        • #19
          I took out the handler and the SetStructureCreate function as I had it in my head you couldn't work within a structure deceleration, this works fine and only lets you create one icon (dont know if thats by design?)

          Code:
          ---Global MemoryEx plugin needed
          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";
          };
                  TTIi = {
          
                      DllVersionInfo = function()
                       local OS = System.GetOSName();
                       if OS == "" then
                        return false, "Can't determine OS"
                       end
                       if OS == "Windows 8" or OS == "Windows Server 2012" or OS == "Windows 7" or OS == "Windows Server 2008 R2" or OS == "Windows Vista" or OS == "Windows Server 2008" then
                        TTIi.UVERS = NOTIFYICON_VERSION_4
                        if OS == "Windows 8" or OS == "Windows Server 2012" or OS == "Windows 7" or OS == "Windows Server 2008 R2" then
                         TTIi.GUID = 0
                        else
                         TTIi.GUID = 0
                        end
                        TTIi.VersionSet = 1
                        return true, "OK"
                       end
                       if OS == "Windows XP" or OS == "Windows Server 2003" then
                        TTIi.UVERS = NOTIFYICON_VERSION_4
                        TTIi.MainStructSize = NOTIFYICON_VERSION
                        TTIi.VersionSet = 1
                        TTIi.GUID = 0
                        return true, "OK"
                       else
                        return false, "OS not supported"
                       end
                      end;
          
                      DestroyIcon = function(sIcon)
                        local hIcon = User32Library.DestroyIcon(sIcon)
                        if hIcon ~= 0 then
                         return true, "OK"
                        else
                         return false, "Can't destroy icon"
                        end
                       end;
          
                      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;
          
          			 };
          
                  TTI = {
          
                      CreateTrayIcon = function(sIcon,sTool)
                       local x,Ih = TTIi.LoadIcon(sIcon)
                       if not x then
                        return false, Ih
                       end
          			 if TTIi.VersionSet ~= 1 then
                        local x,y = TTIi.DllVersionInfo()
                        if not x then
                         return false, y
                        end
                       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 = 100;
                         hStruct.uFlags = NIF_MESSAGE + NIF_ICON + NIF_TIP;
                         hStruct.uCallbackMessage = 101;
                         hStruct.hIcon = Ih;
                         hStruct.szTip = sTool;
                         hStruct.dwState = NIS_HIDDEN;
                         hStruct.dwStateMask = NIS_HIDDEN;
                         hStruct.szInfo = "";
                         hStruct.uTimeout = 0;
                         hStruct.uVersion = TTIi.UVERS;
                         hStruct.szInfoTitle = "";
                         hStruct.dwInfoFlags = NIIF_NONE;
                         hStruct.guidItem = TTIi.GUID;
                         hStruct.hBalloonIcon = "";	
          			   hStruct.cbSize = TTIi.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();
                        TTIi.DestroyIcon(Ih);
                        return false, "Create tray icon failed"
                       else
                        MemoryEx.Free(lpBuff);
                        hStruct:Close();          
                        TTIi.DestroyIcon(Ih);
                        return true, "OK"
                       end
                      end;
                  };
          
                  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;
          		HWND_MESSAGE = -3;
          
          -- Button On Click
          local x,err = TTI.CreateTrayIcon(_SourceFolder.."\\Autoplay\\Icons\\My Icon.ico","Notification Icon")
          if not x then
           Dialog.Message("",err)
          end
          its within two tables as one is going to be internal t the module this is going in, any ideas on how to get a non main handle call back window?

          Comment


          • #20
            Code:
                         if OS == "Windows 8" or OS == "Windows Server 2012" or OS == "Windows 7" or OS == "Windows Server 2008 R2" or OS == "Windows Vista" or OS == "Windows Server 2008" then
                          TTIi.UVERS = NOTIFYICON_VERSION_4
                          if OS == "Windows 8" or OS == "Windows Server 2012" or OS == "Windows 7" or OS == "Windows Server 2008 R2" then
                           TTIi.GUID = 0
                          else
                           TTIi.GUID = 0
                          end
            This section is also not needed as your setting it to TTIi.GUID = 0 no matter what.
            Plugins or Sources MokoX
            BunnyHop Here

            Comment


            • #21
              Originally posted by kingzooly View Post
              [CODE]
              This section is also not needed as your setting it to TTIi.GUID = 0 no matter what.
              NOTIFYICON_VERSION_4 is the default but it can be set differently for vista/7/8 so its default for now till the icon works

              Comment


              • #22
                Originally posted by Shrek View Post
                NOTIFYICON_VERSION_4 is the default but it can be set differently for vista/7/8 so its default for now till the icon works

                I didn't mean to copy that top line in sorry just the
                Code:
                if OS == "Windows 8" or OS == "Windows Server 2012" or OS == "Windows 7" or OS == "Windows Server 2008 R2" then
                	TTIi.GUID = 0
                else
                	TTIi.GUID = 0
                end
                Plugins or Sources MokoX
                BunnyHop Here

                Comment


                • #23
                  i have subclassed the main AMS window with almost every object plugin i have made and have ONLY ever run into problem when custom drawing objects, you should be fine subclassing for this

                  you only get one icon coz your trying to reuse the same id

                  change:

                  CreateTrayIcon = function(iID, sIcon,sTool)
                  local x,Ih = TTIi.LoadIcon(sIcon)
                  if not x then
                  return false, Ih
                  end
                  if TTIi.VersionSet ~= 1 then
                  local x,y = TTIi.DllVersionInfo()
                  if not x then
                  return false, y
                  end
                  end
                  local lpBuff = MemoryEx.Allocate(MemoryEx.StructSize(NOTIFYICONDA TA) + 100);
                  if(lpBuff)then
                  hStruct = MemoryEx.AssignStruct(lpBuff + 50,NOTIFYICONDATA);
                  if(hStruct)then
                  hStruct.hWnd = Application.GetWndHandle();
                  hStruct.uID = iID;
                  and

                  local x,err = TTI.CreateTrayIcon(101, _SourceFolder.."\\AutoPlay\\Icons\\cdpencil.ico"," Notification Icon")
                  and you can have many icone all with independent id's

                  local x,err = TTI.CreateTrayIcon(101, _SourceFolder.."\\AutoPlay\\Icons\\cdpencil.ico"," Notification Icon")
                  if not x then
                  Dialog.Message("",err)
                  end

                  local x,err = TTI.CreateTrayIcon(102, _SourceFolder.."\\AutoPlay\\Icons\\cdpencil.ico"," Notification Icon")
                  if not x then
                  Dialog.Message("",err)
                  end
                  Embrace change in your life, you never know, it could all work out for the best

                  Comment


                  • #24
                    Originally posted by kingzooly View Post
                    I didn't mean to copy that top line in sorry just the
                    Code:
                    if OS == "Windows 8" or OS == "Windows Server 2012" or OS == "Windows 7" or OS == "Windows Server 2008 R2" then
                    	TTIi.GUID = 0
                    else
                    	TTIi.GUID = 0
                    end

                    Windows 7 and later: A registered GUID that identifies the icon. This value overrides uID and is the recommended method of identifying the icon. The NIF_GUID flag must be set in the uFlags member.
                    Windows XP and Windows Vista: Reserved; must be set to 0.

                    Contains information that the system needs to display notifications in the notification area. Used by Shell_NotifyIcon. (ANSI)


                    both are zero as one has to be and the other is default as I haven't got that far lol, there is so many combinations of options depending on the os lol

                    Comment


                    • #25
                      My point is you have set this 100% the same so its really not needed at this point, you just include one TTIi.GUID if your going to set them to the same value anyway right?
                      Plugins or Sources MokoX
                      BunnyHop Here

                      Comment


                      • #26
                        Originally posted by RizlaUK View Post
                        i have subclassed the ma.......
                        Cheers, its working with two now on with subclassing lol.........

                        Comment


                        • #27
                          I am sure this could be cut down:
                          Code:
                                      DllVersionInfo = function()
                                       local OS = System.GetOSName();
                                       if OS == "" then
                                        return false, "Can't determine OS"
                                       end
                                       if OS == "Windows 8" or OS == "Windows Server 2012" or OS == "Windows 7" or OS == "Windows Server 2008 R2" or OS == "Windows Vista" or OS == "Windows Server 2008" then
                                        TTIi.UVERS = NOTIFYICON_VERSION_4
                                        if OS == "Windows 8" or OS == "Windows Server 2012" or OS == "Windows 7" or OS == "Windows Server 2008 R2" then
                                         TTIi.GUID = 0
                                        else
                                         TTIi.GUID = 0
                                        end
                                        TTIi.VersionSet = 1
                                        return true, "OK"
                                       end
                                       if OS == "Windows XP" or OS == "Windows Server 2003" then
                                        TTIi.UVERS = NOTIFYICON_VERSION_4
                                        TTIi.MainStructSize = NOTIFYICON_VERSION
                                        TTIi.VersionSet = 1
                                        TTIi.GUID = 0
                                        return true, "OK"
                                       else
                                        return false, "OS not supported"
                                       end
                          To

                          Code:
                          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
                          		TTIi.MainStructSize = NOTIFYICON_VERSION
                          	end
                          	TTIi.VersionSet = 1
                          	TTIi.GUID = 0
                          	return true, "OK"
                          end
                          As you are just resetting them to the same value.
                          Plugins or Sources MokoX
                          BunnyHop Here

                          Comment


                          • #28
                            It can be, all I was doing was getting it so you could use all available methods hence the abundance of if's but you know perhaps just the default behavior as long as the balloons and callbacks work would be easier

                            Comment


                            • #29
                              the default behavior as long as the balloons and callbacks work
                              i always like to offer as much configuration as i can with my plugins, get the basic system up then fall back and add the goodies would be my advice

                              Cheers, its working with two now on with subclassing lol.........
                              one step ahead

                              Code:
                              ---Global MemoryEx plugin needed
                              Debug.ShowWindow();
                              WM_LBUTTONDOWN = 0x0201;
                              WM_LBUTTONUP = 0x0202;
                              WM_RBUTTONDOWN = 0x0204;
                              WM_RBUTTONUP = 0x0205;
                              WM_CONTEXTMENU = 0x007B;
                              function TTI_Callback(hwnd, umsg, wParam, lParam)
                              	Subclass.OldWinProc(hwnd, umsg, wParam, lParam);
                              	if umsg == WM_CONTEXTMENU then
                              		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
                              	
                              end
                              Subclass.Create(Application.GetWndHandle(), TTI_Callback);
                              set
                              hStruct.uCallbackMessage = WM_CONTEXTMENU;
                              thats ya basic subclassing, on ya own now im going bed, lol, good luck :yes


                              FYI: change WM_CONTEXTMENU to WM_USER and set a custom message to avoid conflict with other parts of the app
                              Embrace change in your life, you never know, it could all work out for the best

                              Comment


                              • #30
                                ^^cheers, heres a bit of an update:

                                --Delete tray icon added
                                --Change tooltip added
                                --Change icon added
                                --Callback added

                                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.DestroyIcon = 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.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.DestroyIcon(Ih);
                                  return false, "Create tray icon failed"
                                 else
                                  MemoryEx.Free(lpBuff);
                                  hStruct:Close();  
                                  Tray.DestroyIcon(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.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.ChangeTrayIcon = 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.DestroyIcon(Ih);
                                  return false, "Change icon failed"
                                 else
                                  MemoryEx.Free(lpBuff);
                                  hStruct:Close();
                                  Tray.DestroyIcon(Ih);
                                  return true, "OK"
                                 end
                                end;
                                
                                function Tray.Callback(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())
                                Still to do:

                                --Balloon tip with sound/without sound with system icon/custom icon
                                --Balloon callbacks:
                                -- Balloon show
                                -- Balloon hide
                                -- Balloon timeout
                                -- Balloon clicked dismissed
                                -- Balloon clicked -- if exists
                                --Get tray icon rectangle
                                --Set focus
                                --Error checking

                                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.

                                Comment

                                Working...
                                X