2017-05-30 15 views
2

Web検索では、アプリケーションが強制終了されたときにWindowsトレイ通知領域に残っている迷子アイコンをクリアする方法を示すサンプルコードをいくつか見つけます(例:Task Managerまたはアップデーターアプリケーション)。例えば、this CodeProject exampleまたはthis blog postです。使用上の通知領域(Windows CE)のアイコンをリフレッシュする

どちらの例も同様の技術は、およびWindows XP上で動作することが報告されている、7、8.1及び10

しかし、どのように彼らは、.NET Compact Frameworkを使用してのWindows CE上で作業を取得するには? 1つの問題は、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)); 
    } 
} 
関連する問題