我有以下代码段
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。
我有什么问题吗?