Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何通过shell执行实现Chrome的最大化?_C++_Windows_Google Chrome - Fatal编程技术网

C++ 如何通过shell执行实现Chrome的最大化?

C++ 如何通过shell执行实现Chrome的最大化?,c++,windows,google-chrome,C++,Windows,Google Chrome,我正在用app=”启动Chrome浏览器http://...“参数(Chrome应用程序快捷方式)通过C++。现在它似乎以大约400x800的大小打开,这是疯狂的。我想最大化地打开它,或者至少让它记住大小 有没有办法做到这一点?--start maximized应该可以做到这一点。 取自 不过我自己还没有测试过。如果您不介意使用默认浏览器(我认为这是最好的选择),而不是强制使用Chrome,您只需打开URL,并指定希望窗口最大化: #include <windows.h> #incl

我正在用
app=”启动Chrome浏览器http://...“参数(Chrome应用程序快捷方式)通过C++。现在它似乎以大约400x800的大小打开,这是疯狂的。我想最大化地打开它,或者至少让它记住大小

有没有办法做到这一点?

--start maximized应该可以做到这一点。 取自
不过我自己还没有测试过。

如果您不介意使用默认浏览器(我认为这是最好的选择),而不是强制使用Chrome,您只需打开URL,并指定希望窗口最大化:

#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 */
}

请注意,您可以尝试使用
dwX
/
dwY
/
dwXSize
/
dwYSize
结构成员为窗口指定默认大小/位置,但我不确定Chrome是否遵守这些设置。

如何启动它?(
CreateProcess
ShellExecute
,…)我使用的是
\u popen
(Windows)。@Matteo:但如果你知道如何使用
CreateProcess
或其他方法,我很高兴听到!我必须打开Chrome,我在变量中知道它的路径。我还需要指定一个参数。这是一个问题吗?您可以重新调整此代码以使用它,但是如果您有特定的路径,最好使用
CreateProcess
,并且不要使用shell。我会在2分钟内发布代码。我无法让它工作。我可以使它工作
SW\u showmized
等,但使用
SW\u showmized
它就是不工作。什么也没发生。如果在创建进程之后尝试调整大小,则会出现访问冲突。代码:您的代码中充满了错误:首先,我明确指出第二个参数必须是可写缓冲区,而该参数为非常量正是出于这个原因。您不应该只在那里放置一个
const\u cast
,而是传递一个可修改的
char*
或将
const char*
复制到一个缓冲区中。然后,在
if
中,不关闭句柄就是在泄漏句柄。但最重要的是,将
hProcess
强制转换为
HWND
没有任何意义:它是一个进程句柄,而不是一个窗口句柄,很明显,您会遇到访问冲突@马特奥:谢谢你的反馈。下面是更新的代码:Chrome似乎没有检测到SW_showmized/MAXIMIZED值。你有什么建议吗?
#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
}