C++: Create a Popup

Started by
3 comments, last by Zahlman 17 years, 6 months ago
What can I write inside of the main() that will pop-up a webpage in an external browser? So I need to create a thread running the default browser and open up a certain webpage... I've tried

system("http://www.blah.com")
I thought this would work. It spawns and quickly closes a DOS box. The system function should tell the OS to open that webpage, and that should spawn the default browser... is that not right? I suppose the other option would be to

WinExec("...iexplorer[firefox].exe http://www.blah.com");
What is the best option? It seems the system function should do exactly what I want, right? Any suggestions?
-------Harmotion - Free 1v1 top-down shooter!Double Jump StudiosBlog
Advertisement
ShellExecute or CreateProcess seem like pretty good options.
I originally saw something about ShellExecute, but disregarded it for some reason or another. It worked great, thanks.
-------Harmotion - Free 1v1 top-down shooter!Double Jump StudiosBlog
system("start http://www.blah.com") would work too, though ShellExecute is definately the preferred way.
.
Quote:Original post by blaze02
What can I write inside of the main() that will pop-up a webpage in an external browser?

So I need to create a thread running the default browser and open up a certain webpage... I've tried
system("http://www.blah.com")

I thought this would work. It spawns and quickly closes a DOS box. The system function should tell the OS to open that webpage, and that should spawn the default browser... is that not right?


No. system() simply sends a command to the OS directly, assuming it has a facility for understanding text commands (good luck on Mac OS pre OS X, for example), and the URL itself is not a command:

C:\Documents and Settings\some body>http://www.blah.com'http:' is not recognized as an internal or external command,operable program or batch file.


As noted, start http://www.blah.com should work. 'start' is a program with a bit of intelligence to it; it reads its command line arguments, and can recognize (for example) URLs as bits of data that it should handle by launching the system's default web browser and pointing it at that URL.

But seriously, if this sort of thing is the primary purpose of your "program", you *don't* want to do it in C++. Use the right tool for the job: a script language like .bat (or even Python or Perl).

This topic is closed to new replies.

Advertisement