C# 刷新通知区域中的图标(Windows CE)

C# 刷新通知区域中的图标(Windows CE),c#,compact-framework,windows-ce,C#,Compact Framework,Windows Ce,web搜索会找到几篇文章,其中的示例代码显示了在应用程序被终止时如何清除留在Windows托盘通知区域中的游离图标(例如通过任务管理器或更新程序应用程序)。例如或 上面的两个例子都使用了类似的技术,并且据报道都可以在WindowsXP、7、8.1和10上使用 但是如何让他们使用.NET Compact Framework在Windows CE上工作呢?一个问题是,FindWindowEx是必需的…但在coredll.dll中不可用基于问题中链接的问题,我终于找到了一个有效的解决方案。我希望这对以

web搜索会找到几篇文章,其中的示例代码显示了在应用程序被终止时如何清除留在Windows托盘通知区域中的游离图标(例如通过
任务管理器
或更新程序应用程序)。例如或

上面的两个例子都使用了类似的技术,并且据报道都可以在WindowsXP、7、8.1和10上使用


但是如何让他们使用.NET Compact Framework在Windows CE上工作呢?一个问题是,
FindWindowEx
是必需的…但在
coredll.dll

中不可用基于问题中链接的问题,我终于找到了一个有效的解决方案。我希望这对以后在Windows CE/Mobile上遇到类似问题的其他人有所帮助

[DllImport("coredll.dll")]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

[DllImport("coredll.dll")]
public static extern IntPtr SendMessage(IntPtr hWnd, int nMsg, IntPtr wParam, IntPtr lParam);

private const int WM_MOUSEMOVE = 0x0200;

public static void RefreshTrayArea()
{
    // The client rectangle can be determined using "GetClientRect" (from coredll.dll) but
    // does require the taskbar to be visible. The values used in the loop below were
    // determined empirically.
    IntPtr hTrayWnd = FindWindow("HHTaskBar", null);
    if (hTrayWnd != IntPtr.Zero)
    {
        int nStartX = (Screen.PrimaryScreen.Bounds.Width / 2);
        int nStopX = Screen.PrimaryScreen.Bounds.Width;
        int nStartY = 0;
        int nStopY = 26;    // From experimentation...
        for (int nX = nStartX; nX < nStopX; nX += 10)
            for (int nY = nStartY; nY < nStopY; nY += 5)
                SendMessage(hTrayWnd,
                    WM_MOUSEMOVE, IntPtr.Zero, (IntPtr)((nY << 16) + nX));
    }
}
[DllImport(“coredll.dll”)]
公共静态外部IntPtr FindWindow(字符串lpClassName,字符串lpWindowName);
[DllImport(“coredll.dll”)]
公共静态外部IntPtr SendMessage(IntPtr hWnd、int nMsg、IntPtr wParam、IntPtr lParam);
私有常量int WM_MOUSEMOVE=0x0200;
公共静态无效刷新Trayarea()
{
//客户端矩形可以使用“GetClientRect”(来自coredll.dll)确定,但是
//不要求任务栏可见。下面循环中使用的值为
//根据经验确定的。
IntPtr hTrayWnd=FindWindow(“HHTaskBar”,null);
如果(hTrayWnd!=IntPtr.Zero)
{
int nStartX=(Screen.PrimaryScreen.Bounds.Width/2);
int nStopX=Screen.PrimaryScreen.Bounds.Width;
int nStartY=0;
int nStopY=26;//来自实验。。。
对于(int nX=nStartX;nX