我能够通过使用FindWindow和lpWindowname隐藏进程(selenium chrome浏览器),方法是将带有Javascript的document.title更改为特定的Window Name以隐藏进程。但是我希望能够通过不同的句柄隐藏进程(selenium chrome浏览器),因为我的程序导航到不同的网站,因此,每次更改窗口名称。
这是我的代码:
[DllImport("user32.dll")]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
const int SW_HIDE = 0;
const int SW_SHOW = 5;
private void button1_Click_1(object sender, EventArgs e)
{
if (on)
{
IntPtr hWnd = FindWindow(null, "Window Name - Google Chrome");
if (hWnd != IntPtr.Zero)
{
ShowWindow(hWnd, SW_HIDE); // Hide the window
}
button1.Text = "Show";
t.Start();
on = false;
}
else {
IntPtr hWnd = FindWindow(null, "Window Name - Google Chrome");
if (hWnd != IntPtr.Zero)
{
ShowWindow(hWnd, SW_SHOW); //Show Window
}
button1.Text = "Hide";
t.Stop();
on = true;
}