2017-05-30 79 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)); 
    } 
}