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



一个Web搜索找到了几篇文章,其中包含示例代码,显示如何在杀死应用程序时在Windows Tray通知区域中留下的流浪图标(例如,通过Task Manager或更新程序应用程序(。例如,此codeproject示例或此博客文章。

上面的两个示例都使用类似的技术,并据报道在Windows XP,7、8.1和10上使用。

但是如何使用.NET紧凑型框架使它们在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));
    }
}

最新更新