我有以下代码片段
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 个程序返回任何值,但会返回一个无标题 - 记事本。
有什么我做错了吗?