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

标签 c# compact-framework windows-ce

通过网络搜索可以找到几篇带有示例代码的文章,其中展示了如何在应用程序被终止(例如,通过任务管理器 或更新程序应用程序)时清除 Windows 托盘通知区域中留下的杂散图标。例如this CodeProject examplethis blog post .

上面的两个例子都使用了类似的技术,据报道可以在 Windows XP、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));
    }
}

关于c# - 刷新通知区域中的图标 (Windows CE),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44265446/

相关文章:

c# - 在 C# 中检测网络状态(连接 - 断开连接)

crash - 应用程序崩溃时,没有致命异常的迹象NLog版本2 |紧凑框架3.5

javascript - 在 Windows CE 上用 JScript 绘图

c# - 从 ActionFilterAttribute 返回带有模型的 View

c# - 在 .Net Compact Framework 中将文件内容读取为字符串

c# - c#紧凑框架中的Directshow : trigger handling problems for a Filtergraph's IMediaEvent

windows-ce - 为非 x86 目标自定义引导加载程序闪屏

c# - 将文档从 MVC 网页保存到第二个 RavenDb

c# - 如何从浏览器应用程序控制扫描仪?

c# - 将两个小数列表组合在一个数组中