我已经在我的应用程序中添加了一个通知图标,并且经常在我的系统托盘中看到多达3个通知图标的副本。这是有原因的吗?
有没有办法阻止它的发生。
这通常在我的应用程序关闭后仍然存在,直到我更多地转移到systray,systray展开和折叠,然后它们都消失了。
发布于 2009-03-17 13:24:55
这是在你调试你的应用的时候吗?如果是这样,这是因为只有当应用程序正常退出时,才会发送从系统托盘中删除图标的消息,如果应用程序因为异常或因为您从Visual Studio中终止它而终止,则图标将一直保留,直到您将鼠标悬停在图标上。
发布于 2012-04-08 19:43:32
您可以使用父窗口的Closed事件终止图标。这在我的WPF应用程序中有效,即使在Visual Studio中测试时也是如此(在我的例子中是2010):
parentWindow.Closing += (object sender, CancelEventArgs e) =>
{
notifyIcon.Visible = false;
notifyIcon.Icon = null;
notifyIcon.Dispose();
};发布于 2012-06-01 01:14:21
我做了什么:
使用系统;使用System.Diagnostics;使用System.Runtime.InteropServices;命名空间SystrayUtil {内部枚举MessageEnum { WM_MOUSEMOVE = 0x0200,WM_CLOSE = 0x0010,}内部结构RECT {内部int left;internal int Top;internal int Right;internal int Bottom;internal RECT(int left,int top,int right,int RECT){ Left = Left;Top =上;右=右;下=下;}}公有密封类Systray { DllImport("user32.dll",SetLastError = true)私有静态外部IntPtr FindWindow(string lpClassName,string lpWindowName);DllImport("user32.dll",SetLastError = true)私有静态外部IntPtr FindWindowEx(IntPtr hwndParent,IntPtr hwndChildAfter,string lpszClass,IntPtr lpszWindow);DllImport("user32.dll",SetLastError = true)私有静态外部IntPtr SendMessage(IntPtr hWnd,int message,uint wParam,long lParam);DllImport("user32.dll",SetLastError = true)私有外部静态布尔GetClientRect(IntPtr hWnd,out RECT usrTray);公共静态空清理(){ RECT sysTrayRect = new RECT();IntPtr sysTrayHandle = FindWindow("Shell_TrayWnd",null);if (sysTrayHandle != IntPtr.Zero) { IntPtr childHandle = FindWindowEx(sysTrayHandle,IntPtr.Zero,"TrayNotifyWnd",IntPtr.Zero);if (childHandle != IntPtr.Zero) { childHandle = FindWindowEx(childHandle,IntPtr.Zero,"SysPager",IntPtr.Zero);if (childHandle != IntPtr.Zero) { childHandle = FindWindowEx (childHandle,IntPtr.Zero,"ToolbarWindow32",IntPtr.Zero);if (childHandle != IntPtr.Zero) { bool systrayWindowFound = GetClientRect(childHandle,out sysTrayRect);if (systrayWindowFound) { for (int x= 0;x< sysTrayRect.Right;x += 5) { for (int y= 0;y< sysTrayRect.Bottom;Y += 5) { SendMessage(childHandle,(int)MessageEnum.WM_MOUSEMOVE,0,(y << 16) + x);}
"%ProgramFiles%\Microsoft Visual Studio x.x\Common7\IDE\PublicAssemblies\SystrayUtil.dll"其中x.x是Visual Studio
添加对创建的dll的引用。
将Imports SystrayUtil添加到模块EnvironmentEvents顶部的导入列表中。
删除所有不需要的项,并将以下代码添加到EnvironmentEvents模块
公有子DebuggerEvents_OnEnterDesignMode(ByVal Reason As EnvDTE.dbgEventReason)处理DebuggerEvents.OnEnterDesignMode Systray.Cleanup() MsgBox(“进入设计模式!”)End Sub
MsgBox("Entered design mode!"),因为每次从调试会话返回时都弹出一个消息框,这很烦人。https://stackoverflow.com/questions/654212
复制相似问题