[英]How to maximize/ minimize currently opened Firefox window through C#
I'm trying to create a windows form in C#, where I would press a button and then my minimized Firefox tab would maximize or at least open up.我正在尝试在 C# 中创建一个 windows 表单,我将在其中按下一个按钮,然后我最小化的 Firefox 选项卡将最大化或至少打开。 Everything I tried just makes a new Firefox window instead of opening the current one I have.
我尝试的所有东西都只是制作了一个新的 Firefox window 而不是打开我现有的一个。 I don't know how to do this.
我不知道该怎么做。 I tried ShowWindowAsync but I didn't really understand it.
我试过 ShowWindowAsync 但我并不真正理解它。
This is my working Console application:这是我的工作控制台应用程序:
using System;
using System.Linq;
using System.Diagnostics;
using System.Runtime.InteropServices;
class Program
{
[DllImport("user32.dll")]
private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
static void Main()
{
var firefox = Process.GetProcessesByName("firefox").FirstOrDefault();
if (firefox != null)
{
SetProcessWindowState(firefox, WindowState.ShowNormal);
}
}
static void SetProcessWindowState(Process process, WindowState windowState)
{
ShowWindow(process.MainWindowHandle, (int)windowState);
}
}
enum WindowState
{
Maximize = 3, Minimize = 6, ShowNormal = 1
}
For more information about ShowWindow look here .有关 ShowWindow 的更多信息,请查看此处。
EDIT: it turns out that the newest version of Firefox runs multiple processes in the background:编辑:事实证明,最新版本的 Firefox 在后台运行多个进程:
var firefoxProcesses = Process.GetProcessesByName("firefox");
foreach (var firefox in firefoxProcesses)
{
SetProcessWindowState(firefox, WindowState.ShowNormal);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.