有些Window应用程序在启动以后会在系统托盘去添加一个小图标, 一般情况下当程序正常退出时会自动去掉,但有时由于应用程序非法关闭,这个图标便一直留在托盘区,直到用鼠标移动图标上时,才会自己消失发。那么如何用C#实现自动移去系统托盘失效的图标
解决方案 »
- 谁能简述一个C#实际案例?
- 两台并非集群的服务器,如何动态选择在线的服务器?
- 我写了两个组件,一个组件A从网络上接收数据,另一个组件B把A接收到的数据显示成曲线。B怎样才能读取A的数据?
- 问专家:C#程序怎么使用服务上的4个CPU工作
- 请问各位高手如何实现点击窗体任何地方都能拖动窗体的功能???
- 请问,如何获得网页或图片等文件的文件信息!!!
- Net WCF遍历方法参数
- 值得探讨的一个问题,进者有分
- DataGrid的一个问题?
- winform 中 A窗体有一个DataTable,A窗体跳转B窗体,再跳转A,现在A中DataTable中的值不能清空
- 如何清空缓冲区?
- 服务 OrderReportService 意外停止。这发生了 5 次。
都结束了,怎么能控制任务栏图标失效呢,Windows就是这样设计的,所有系统指示器图标都会这样。
{
HWND hTrayWindow;
RECT rctTrayIcon;
int nIconWidth;
int nIconHeight;
TPoint CursorPos;
int nRow;
int nCol;
// Get tray window handle and bounding rectangle
hTrayWindow = FindWindowEx(FindWindow(
"Shell_TrayWnd", NULL), 0, "TrayNotifyWnd", NULL);
if(!GetWindowRect(hTrayWindow, &rctTrayIcon))
return;
// Get small icon metrics
nIconWidth = GetSystemMetrics(SM_CXSMICON);
nIconHeight = GetSystemMetrics(SM_CYSMICON);
// Save current mouse position }
GetCursorPos(&CursorPos);
// Sweep the mouse cursor over each icon in the tray in both dimensions
for(nRow=0; nRow<(rctTrayIcon.bottom-rctTrayIcon.top)/nIconHeight; nRow++)
{
for(nCol=0; nCol<(rctTrayIcon.right-rctTrayIcon.left)/nIconWidth; nCol++)
{
SetCursorPos(rctTrayIcon.left + nCol * nIconWidth + 5,
rctTrayIcon.top + nRow * nIconHeight + 5);
Sleep(0);
}
}
// Restore mouse position
SetCursorPos(CursorPos.x, CursorPos.x);
// Redraw tray window (to fix bug in multi-line tray area)
RedrawWindow(hTrayWindow, NULL, 0, RDW_INVALIDATE | RDW_ERASE | RDW_UPDATENOW);
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
Application.Exit();
}
notifyIcon1.Dispose();