Minimize application programmatically using C #
I have the following piece of code
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);
}
}
Where sensitiveApps is a list containing the strings "Notepad", "Recuva" and "VLC media player 2.0.3".
However, the only application that can be minimized with this code is Notepad. Debugging the program finds that
Console.WriteLine(stringBuilder.ToString());
will return no value for the last two programs, but will return Untitled-Notepad.
Is there something I am doing wrong?
+3
source to share