次のコードスニペットがあります
List<String> sensitiveApps = testConnection.SelectSensitive();
foreach (string sensitiveApp in sensitiveApps)
{
Console.Write(sensitiveApp);
// retrieve applications to minimize handle (connect to database and systematically minimize all applications?)
IntPtr hwnd = UnsafeNativeMethods.FindWindow(sensitiveApp, null);
StringBuilder stringBuilder = new StringBuilder(256);
UnsafeNativeMethods.GetWindowText(hwnd, stringBuilder, stringBuilder.Capacity);
Console.WriteLine(stringBuilder.ToString());
if (!hwnd.Equals(IntPtr.Zero))
{
// SW_SHOWMAXIMIZED to maximize the window
// SW_SHOWMINIMIZED to minimize the window
// SW_SHOWNORMAL to make the window be normal size
ShowWindowAsync(hwnd, SW_SHOWMINIMIZED);
}
}
sensitiveApps は、"Notepad"、"Recuva"、および "VLC media player 2.0.3" という文字列を含むリストです。
ただし、このコードを使用して最小化できるアプリケーションはメモ帳だけです。プログラムをデバッグすると、
Console.WriteLine(stringBuilder.ToString());
最後の 2 つのプログラムの値は返されませんが、Untitled - Notepad が返されます。
私が間違っていることはありますか?