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.