2017-05-30 66 views
2

网络搜索会找到多个文章,其中包含示例代码,显示如何在应用程序被终止时(例如,通过Task Manager或更新程序应用程序)清除Windows托盘通知区域中残留的杂散图标。例如this CodeProject examplethis blog post通知区域(Windows CE)中的刷新图标

使用以上两个例子类似的技术,据报道,在Windows XP上运行,7,8.1和10

但如何让他们在Windows CE使用.NET Compact Framework的工作?一个问题是需要FindWindowEx ...但在coredll.dll中不可用。

回答

1

基于问题中的问题,我终于找到了一个可行的解决方案。我希望这可以帮助其他人在将来在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)); 
    } 
}