如何启动Chrome最大化通过shell执行
How to launch Chrome maximized via shell execution?
我通过c++启动带有app="http://..."
参数(Chrome应用程序快捷方式)的Chrome。现在它似乎以大约400x800的大小打开,这太疯狂了。我想把它打开到最大或者至少让它记住大小。
有办法做到这一点吗?
如果你不介意使用默认浏览器(在我看来,这是最好的选择)而不是强制使用Chrome,你可以简单地打开你的URL与ShellExecute
指定你想要最大化的窗口:
#include <windows.h>
#include <Shellapi.h>
// requires linking towards Shell32.lib
// ...
if(ShellExecute(NULL, "open", "http://www.stackoverflow.com", NULL, NULL, SW_SHOWMAXIMIZED)<=32)
{
/* an error occurred */
}
我必须打开Chrome,并且我在变量中知道它的路径。我还需要指定一个参数。这是个问题吗?
在这种情况下,最好使用CreateProcess
:
#include <windows.h>
// ...
// Assuming that the path to chrome is inside the chromePath variable
// and the URL inside targetURL
// Important: targetURL *must be* a writable buffer, not a string literal
// (otherwise the application may crash on Unicode builds)
PROCESS_INFORMATION processInformation;
STARTUPINFO startupInfo;
memset(&processInformation, 0, sizeof(processInformation));
memset(&startupInfo, 0, sizeof(startupInfo));
startupInfo.cb = sizeof(startupInfo);
startupInfo.wShowWindow = SW_SHOWMAXIMIZED;
BOOL result= CreateProcess(chromePath, targetURL, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS, NULL, NULL, &startupInfo, &processInformation);
if(result)
{
WaitForSingleObject( processInformation.hProcess, INFINITE );
CloseHandle( processInformation.hProcess );
CloseHandle( processInformation.hThread );
}
else
{
// An error happened
}
请注意,您可以尝试使用STARTUPINFO
结构的dwX
/dwY
/dwXSize
/dwYSize
成员指定窗口的默认大小/位置,但我不确定Chrome是否尊重这些设置。
——start-maximized应该可以做到。摘自http://peter.sh/experiments/chromium-command-line-switches/不过我自己还没有测试过……
相关文章:
- 如何通过cpp程序运行shell脚本
- 如何将c++程序的一些输出传递给shell,以便在shell中使用
- shell排序中的交换和比较
- 最大化数组总和
- 我适合在我的构建系统中使用 shell 脚本而不是AX_CHECK_COMPILE_FLAG吗?
- GTK 最大化表单 C++
- 使用提升过程获取 shell 命令的标准输出
- 终端如何在 shell 提示符下以编程方式阻止退格,以便您无法在其上退格,例如 $ 表示 bash 或 C:\blah\>
- CMake 引用我在 ~/bin 中创建的随机 shell 脚本(即使我删除了它)?
- 如何在 Linux 下执行 shell 命令 unsing QProcess?
- 在 c++ 中从执行的 shell 命令获取返回状态的安全方法是什么?
- 如何在C++中最大化SSD I / O?
- 使用 2x1 图块平铺 2xM 数组以最大化差异 - INOI 2008,P2
- 等效的Windows API与Power shell get-physicaldisk命令
- 如何在有限的分叉数量下运行类似shell的管道任务
- 从带有参数的C++程序中调用shell脚本
- wx帧缺少最大化按钮
- 在 QProcess 中执行 shell 命令
- 如何隐藏最大化和最小化按钮并在qml应用程序窗口中显示关闭按钮?
- 如何启动Chrome最大化通过shell执行