Question

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?

Était-ce utile?

La solution

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

MS Word is OpusApp and VLC is QWidget.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top