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

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.

Related

How to launch IE from C++ code and be able to get html data after web page is changed

Here is my problem:
I am about to implement a method (C++),with an URL argument as parameter, what this method do is to launch the default browser of windows,and visit the url; this URL leads to an page, user of this program have to fill in some info in this page,and submit, then it jump to result page, and my method need to read and analyze this page data.
I know how to launch an browser like IE , but how to:
read page data to my program?
how my program know the page in browser is updated?
Maybe I should just write a web browser inside my program?
Looks like you want to do the IE browser automation. In which you want to launch the IE and try to fetch data from the web page.
With only C++ you can open the IE browser using shell and open the URL but you will not be able to fetch the data to your application.
I suggest you to check the documentation for Selenium Web driver.
I check and find that currently no any framework available for C++.
If you are available to use C# or JavaScript than it can help to solve your issue.
Reference:
Programming Languages & Frameworks
If you are available to use VBA than you can also refer link below for IE automation using VBA.
(1) Automate Internet Explorer (IE) Using VBA
(2) IE (Internet Explorer) Automation using Excel VBA
(3) VBA Internet Explorer Object

Webbrowser Active X custom dynamic MIME handler pdf

I am using Microsoft's Web Browser ActiveX control in an MFC application.
I want to be able to change the default MIME handler for PDF.
https://msdn.microsoft.com/en-us/library/ie/ms775148(v=vs.85).aspx
It appears to me that web browser control must use the registry based file type association
HKEY_CLASSES_ROOT\MIME\Database\Content Type\application/pdf
I want to be able to set web browser control to use the pdf application
I tell it to use at runtime, rather than using the system registered default.
I cannot find any API that will allow me to do this. Is it possible?
I initially proposed in the comments to create an Asynchronous Pluggable Protocol handler to customize the player for this MIME type, but I think there might be an easier approach.
You might be able to redirect the HKEY_CLASSES_ROOT\MIME\Database\Content Type\application/pdf registry key to your own custom version (per-process) with RegOverridePredefKey API, as explained here.

Invoking Win32 application from email body

I am working in an application. In this user enter his email id to get the some application setting.
After some time he will get mail with settings embedded and an apply button. Once user click on that we need to set the setting (in some file or registry).
Desktop application will read the setting(File / Registry) once it is launched.
This is the requirement. My question is,
How to call Win32/MFC application on clicking apply button with setting parameter.
You cannot arbitrarily execute something in an email message for obvious reasons.
The closest integration you could get would be to pass the configuration data as an argument to a custom URL handler in an HTML anchor; your mileage would likely vary wildly depending on browser/email client/webmail service so this is a bad idea.
Far better to simply send the configuration as an attachment with a file extension associated with your application and tell the user to open it, your app reads the config file and your done.

MFC : How to capture a link click event in a web browser control?

I have an MFC application that has a webcontrol. When clickable links are clicked, it opens using IE, not the default browser.
Questions :
Is there a way to force it to open using the default browser?
If not, how do I capture the Link Click event so I could just manipulate the click event later?
Thanks...
No, not as far as I know.
Check out the articles on http://ehsanakhgari.org/article/visual-c/webbrowser-goodies . It has a number of articles that show how to set up an event sink using IDocHostUIHandler etc. to handle events like clicking of links. I'm not sure which interface to implement, it's been years since I last did this. Then, you use ShellExecute() with a url as the third parameter to open a url with the default browser.
You can capture click events by using "HRESULT STDMETHODCALLTYPE Invoke" see MSDN for more details.
And here's a great example that shows how to open your URL using the default browser in the same window, or opening a new window > http://www.codeproject.com/KB/IP/urlnewwindow.aspx

Open default browser as standard user (C++)

I'm currently using ShellExecute "open" to open a URL in the user's browser, but running into a bit of trouble in Win7 and Vista because the program runs elevated as a service.
When ShellExecute opens the browser, it seems to read the "Local Admin" profile instead of the user's. So for example, if the user at the keyboard has Firefox as his default browser, it may open IE (which is the admin's default).
I know that the "runas" verb can be used to elevate, but how do you do it the other way around? Is there a way to open a URL in the default browser on a standard user's desktop from a service?
ShellExecute will execute the program in the context of the same session and same user as the process you are running.
If you'd like to use a different session or user token you can use the CreateProcessAsUser Win32 API.
There are several ways to obtain a user token, for example you can call the Win32 API:
LogonUser if you know the username and password
WTSQueryUserToken for any given session ID.
OpenProcessToken if you have another process handle
After a while of testing, the best way to determine the default browser is the following:
NOTE: It is strange but it's true...
It has nothing to say that an application is the default application for
some file type or web protocol like 'http'. What matters to determine the default
web browser is just what is registered in the start menu entry (see reg key below).
So forget all the HKCR\http, HKCU\Software\Classes\http, HKLM\Software\Classes\http and their friends.
read from "HKEY_CURRENT_USER\Software\Clients\StartMenuInternet"
read command line from "HKEY_LOCAL_MACHINE\Software\Clients\StartMenuInternet\\shell\open\command"
truncate the command line after ".exe"
Of course you need to impersonate as the logged on user first.
If this solution does not work (like with w2k), use the handler for the http protocol.
To actually start the default browser from a service we use an extra process which is within the service using the logged on user-context. This process starts the above commandline (using ShellExecute on platforms >= Vista). Be sure to use same integrity level (medium) as a default user (else IE won't work because it uses DDE).
HTH.
Aaron Margosis has a seven-step native code example at http://blogs.msdn.com/aaron_margosis/archive/2009/06/06/faq-how-do-i-start-a-program-as-the-desktop-user-from-an-elevated-app.aspx. Won't help you from your service if that is what you have - I agree your service shouldn't be trying to launch an app as the logged in user, especially since there might not be one.