如何启动Chrome通过shell执行最大化? [英] How to launch Chrome maximized via shell execution?

查看:611
本文介绍了如何启动Chrome通过shell执行最大化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过C ++使用 app =http:// ...参数(Chrome应用程序快捷方式)启动Chrome。现在它似乎打开与大约400x800这是疯狂的大小。



有没有办法实现这个?

解决方案

如果你不介意使用默认浏览器(在我看来是最好的选择),而不是强制使用Chrome,你可以打开你的包含 ShellExecute ,指定您希望窗口最大化:

  #include< windows.h> ; 
#include< Shellapi.h>
//需要连接到Shell32.lib

// ...

if(ShellExecute(NULL,open,http: stackoverflow.com,NULL,NULL,SW_SHOWMAXIMIZED)< = 32)
{
/ *发生错误* /
}
pre>





我必须打开Chrome,我还需要指定一个参数。这是一个问题吗?


在这种情况下,最好使用 CreateProcess

  #include< windows.h> 

// ...

//假设chrome的路径在chromePath变量
//内,并且在targetURL内的URL
/ /重要:targetURL *必须是*可写缓冲区,而不是字符串文字
//(否则应用程序可能在Unicode构建上崩溃)
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
{
//发生错误
}

请注意,您可以尝试使用 dwX / dwY / dwXSize / dwYSize STARTUPINFO 不确定Chrome是否遵守这些设置。


I am launching Chrome with the app="http://..." parameter (a Chrome application shortcut) via C++. Now it seems to open with a size of roughly 400x800 which is crazy. I'd like to open it maximized or at least have it remember the size.

Is there a way to achieve this?

解决方案

If you don't mind using the default browser (which, in my opinion, is the best option) instead of forcing the use of Chrome, you can simply open your URL with ShellExecute specifying that you want the window to be maximized:

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


I must open Chrome, and I have its path known in a variable. I also need to specify one parameter. Is this a problem?

Well, in this case it's better to use 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
}

Notice that you can try to specify a default size/posizion for the window using the dwX/dwY/dwXSize/dwYSize members of the STARTUPINFO structure, but I'm not sure if Chrome respects these settings.

这篇关于如何启动Chrome通过shell执行最大化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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