3

I have the following code snippet

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 using this code is Notepad. Debugging the program finds that

Console.WriteLine(stringBuilder.ToString());

would not return any value for the last 2 programs, but would return a Untitled - Notepad.

Is there anything I'm doing wrong?

David Ten
  • 113
  • 1
  • 10
  • 1
    1. Using [Spy++](http://msdn.microsoft.com/en-us/library/aa264396%28VS.60%29.aspx) the FindWindow names are correct? 2. Recuva & VLC don't have skinning ability? 3. Have you tried using SetWindowText on it and changing the title to something else? – Jeremy Thompson Jan 21 '13 at 04:32
  • Thanks! I had no idea that there was such a program called Spy++... Found out that MS Word is OpusApp, and VLC is QWidget. – David Ten Jan 21 '13 at 04:59

1 Answers1

3

Try using Spy++ and check the FindWindow names are correct.

MS Word is OpusApp and VLC is QWidget.

Jeremy Thompson
  • 61,933
  • 36
  • 195
  • 321