trayicon - prevent more than one tray icon in c# -


i developing application in c#.net,and writing code display icon in system tray,and whenever new message arrives balloon tooltip shown there,which has click event open new message arrived,everything works fine,but problem getting multiple numbers of icon generated in system tray,which shuld one,how can prevent it?i found on internet how dispose them,but couldn't find way prevent more one.or there better way show notifications newly received message..please me if know solution..

there better custom solutions available see here , here examples.

however, system tray doesn't refresh automatically. if show/hide multiple system tray icons, can mess tray up. disposed icons disappear when mouse hover. however, there way refresh system tray programmatically. reference here.

note : sendmessage function, sends specified message window or windows. sendmessage function calls window procedure specified window , not return until window procedure has processed message.

 [structlayout(layoutkind.sequential)]     public struct rect     {         public int left;         public int top;         public int right;         public int bottom;     }     [dllimport("user32.dll")]     public static extern intptr findwindow(string lpclassname, string lpwindowname);     [dllimport("user32.dll")]     public static extern intptr findwindowex(intptr hwndparent, intptr hwndchildafter, string lpszclass, string lpszwindow);     [dllimport("user32.dll")]     public static extern bool getclientrect(intptr hwnd, out rect lprect);     [dllimport("user32.dll")]     public static extern intptr sendmessage(intptr hwnd, uint msg, int wparam, int lparam);       public void refreshtrayarea()     {         intptr systemtraycontainerhandle = findwindow("shell_traywnd", null);         intptr systemtrayhandle = findwindowex(systemtraycontainerhandle, intptr.zero, "traynotifywnd", null);         intptr syspagerhandle = findwindowex(systemtrayhandle, intptr.zero, "syspager", null);         intptr notificationareahandle = findwindowex(syspagerhandle, intptr.zero, "toolbarwindow32", "notification area");         if (notificationareahandle == intptr.zero)         {             notificationareahandle = findwindowex(syspagerhandle, intptr.zero, "toolbarwindow32", "user promoted notification area");             intptr notifyiconoverflowwindowhandle = findwindow("notifyiconoverflowwindow", null);             intptr overflownotificationareahandle = findwindowex(notifyiconoverflowwindowhandle, intptr.zero, "toolbarwindow32", "overflow notification area");             refreshtrayarea(overflownotificationareahandle);         }         refreshtrayarea(notificationareahandle);     }       private static void refreshtrayarea(intptr windowhandle)     {         const uint wmmousemove = 0x0200;         rect rect;         getclientrect(windowhandle, out rect);         (var x = 0; x < rect.right; x += 5)             (var y = 0; y < rect.bottom; y += 5)                 sendmessage(windowhandle, wmmousemove, 0, (y << 16) + x);     } 

Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -