我有如下代码片段。
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);
}
}
敏感应用程序是一个包含字符串“记事本”,“Recuva”和“VLC media player 2.0.3”的列表。
然而,只有记事本可以使用此代码最小化。调试程序发现
Console.WriteLine(stringBuilder.ToString());
最后 2 个程序不会返回任何值,但会返回一个“无标题 - 记事本”。
我做错了什么吗?