简体   繁体   中英

Launch a URL in a NEW window using C++ (Windows)

How can I launch a URL in a NEW window using C++ (Windows only)?

The straight-forward approach seems to open a new tab in an existing browser window. (Or, if tabbed browsing is disabled, the new URL hijacks the existing browser window).

This is for a (large) desktop app, using MFC and Qt.

I've used this for showing locally generated html in the default browser, in my case filename is something like "c:\\temp\\page.html", perhaps replacing filename with the URL might work??

ShellExecute(NULL,"open",filename,NULL,NULL,SW_SHOWNORMAL);

Updated: http://support.microsoft.com/kb/224816

How ShellExecute Determines Whether to Start a New Instance When ShellExecute looks through the registry, it looks for the shell\\open subkey. If the shell\\open\\ddeexec key is defined, then a Dynamic Data Exchange (DDE) message with the specified application IExplore and the topic WWW_OpenURL is broadcast to all top-level windows on the desktop. The first application to respond to this message is the application that goes to the requested URL. If no application responds to this DDE message, then ShellExecute uses the information that is contained in the shell\\open\\command subkey to start the application. It then re-broadcasts the DDE message to go to the requested URL.

So it looks like you have no control over opening a new window. Whatever browser currently running can handle opening it in whatever way they want.

This is controlled by windows. The only way to explicitly tell it to open in a new browser window is to spawn the browser explicitly and give it the url.

Here's a link to some code that will open a URL in a new browser . The code looks up the default application for handling an HTML document and then explicitly opens that application with a ShellExecute call.

You can't in general. The user's browser is free to do whatever the user wants it to do.

One way to achieve your desired effect might be to embed a particular browser in a window of your own (say, the IE ActiveX control) and have that render your URL.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM