c# - 使用 C# 以编程方式最小化应用程序

标签 c# minimize

我有以下代码片段

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 个程序的任何值,但会返回一个无标题 - 记事本。

我做错了什么吗?

最佳答案

尝试使用 Spy++并检查 FindWindow 名称是否正确。

MS Word 是 OpusApp,VLC 是 QWidget。

关于c# - 使用 C# 以编程方式最小化应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14432473/

相关文章:

python - 无法在 scipy 中导入最小化

python - 如何修复错误 : The truth value of an array with more than one element is ambiguous

java - JFrame 最小化为扩展坞名称 "java"

c++ - 在 C++ Windows API 中最小化的应用程序事件

java - 自带最小化按钮效果

c# - 在经典 ASP 中的每个午夜更新应用程序变量

c# - 何时传递 ref 关键字

c# - DDD : Should Persistence Logic belong to Infrastructure Layer?

c# - 如何避免每次启动程序而不是一次生成 Sqlite DB

c# - PostAsJsonAsync 返回 null