Launch browser from within program

Started by
12 comments, last by silverphyre673 18 years, 8 months ago
Is there an easy way to lauch a browser window and direct it automatically to a certain webpage? In the game I just made, I would like to be able to make a button that directs users to my website when clicked. I'm using Windows, and the program is written in C++, using SDL. Thanks!+
my siteGenius is 1% inspiration and 99% perspiration
Advertisement
In windows you can do this:

system("iexplore http://www.hotmail.com");

for example.

Not the best way im sure but it is easy.

ace
You may want to try the ShellExecute() function instead. It should use the user's default web browser.
Thought there would be a better way. Is that including windows.h as well si?

And also presumably the same command as i suggested?

ace
How do you call the default browser? You can tell either Valve doesn't care about it's users defaults or is in bed with Microsoft as Steam upon updates launches IE whenever you click on a link. It's truely annoying. I don't use IE for a reason, I dislike people making decisions for me and for the safety of my PC.
There is probably a registry key that defines the path of the default browser.

ace
Just run the URL, the default browser will open up.

Goto START->RUN and type an URL. :)
Well aware of that feature Vampyre_Dark, but how do you do that with ShellExecute() or system()? :) I tried system and you need more then just the URL (knew it but had to test it). Now I was working with a console app and I'm on my way out the door so I don't have time to load up my windows test app and toss in ShellExecute to try it...

I've been wondering about this myself, I had code awhile ago that let you add URLs into dialog boxes but I cannot find it, as I'm sure it had a solution in it.
ShellExecute is in shellapi.h and will call the default browser.

The default browser is "defined" in HKEY_CLASSES_ROOT under the extension for web files. It will typically be "redirected" from HKR\.htm or HKR\.html to HKEY_CLASSES_ROOT\htmlfiles.

edit: This is how you would use it:
ShellExecute( NULL, "open", "Web page.htm", NULL, NULL, SW_SHOW );


edit2: Some systems will have the "open" verb not be the default verb, so you can use NULL instead of "open", which will call the default action.


jfl.
http://msdn.microsoft.com/msdnmag/issues/05/03/CATWork/

Answered my own question. ShellExecute with just the URL should launch the default browser. I'll confirm later and post if it doesn't.

This topic is closed to new replies.

Advertisement