谷歌浏览器 - 新窗口切换忽略--window位和--window大小 [英] Google Chrome --new-window switch ignores --window-position and --window-size

查看:2204
本文介绍了谷歌浏览器 - 新窗口切换忽略--window位和--window大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图控制通过命令行的规模和新生成的谷歌Chrome浏览器窗口的位置(通过C#)。

I'm trying to control the size and position of newly spawned Google Chrome windows via the command line (through C#.)

我的命令行结束了看起来像

My command line ends up looking like:

--new-window --window-position=100,100 --window-size=800,600 www.UrlToOpen.com

然而,新的窗口刚刚打开过,其中最后的Chrome窗口开始之上。

However, the new window just opens over top of where the last Chrome window was started.

最终的结果我要找的是要能够启动谷歌浏览器的多个实例,在不同的窗口,具有特定的位置和大小。我已经能够做到这一点,到目前为止的唯一方法是通过指定每个实例是有它自己的 - 用户数据目录。然而,这并不理想给了多少扩展的用户可能已经安装了,并且它不会是最好的用户体验。

The end result I'm looking for is to be able to start multiple instances of Google Chrome, in separate windows, with a specific location and size. The only way I've been able to do this so far is by specifying that each instance is to have it's own --user-data-dir. However, this is not ideal given how many extensions a user may have installed, and it would not be the best user experience.

有没有人有什么建议吗?

Does anyone have any suggestions?

推荐答案

如果Chrome无法编程,允许这样做,你只有一个选择。

If Chrome is not programmed to allow this, you only have one option.


  1. 创建过程,并保持过程对象。

  2. 使用的 Process.MainWindowHandle 获得新创建的窗口(您可能需要使用一个循环,并的 Process.Refresh ,或的 Process.WaitForInputIdle

  3. 使用的 SetWindowPos 的原生功能,无论你想它来定位窗口。

  1. Create the process and keep the process object.
  2. Use Process.MainWindowHandle to get the newly created window (you might need to use a loop and Process.Refresh, or Process.WaitForInputIdle)
  3. Use the SetWindowPos native function to position the window wherever you want it.

本机钩可以用来检测窗口的创建,但需要您创建一个非托管的DLL。

Native hooks could be used to detect creation of the window, but that requires you to create an unmanaged DLL.

这篇关于谷歌浏览器 - 新窗口切换忽略--window位和--window大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆