How would I get a C++ program to open a web page in IE or even better in the default browser?
How would I get a C++ program to open a web page in IE or even better in the default browser?
Ok just delete this...I'll use Javascript instead.
Taken from a program of mine:
Code:BOOL CDialogAbout::OpenUrl(CONST std::string& Url) { SHELLEXECUTEINFO Info; ZeroMemory(&Info, sizeof(SHELLEXECUTEINFO)); Info.cbSize = sizeof(SHELLEXECUTEINFO); Info.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_NO_UI; Info.lpFile = Url.c_str(); Info.hInstApp = GetModuleHandle(NULL); Info.nShow = SW_SHOWNORMAL; if(!ShellExecuteEx(&Info)) { Error.SetMessage("Unable to open \"" + Url + "\"!"); return FALSE; } return TRUE; }
MagosX.com
Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.
well, if you're going to be platform specific, you may as well be platform specifc and simple
Code:system("start http://www.cprogramming.com");
"I saw a sign that said 'Drink Canada Dry', so I started"
-- Brendan Behan
Free Compiler: Visual C++ 2005 Express
If you program in C++, you need Boost. You should also know how to use the Standard Library (STL). Want to make games? After reading this, I don't like WxWidgets anymore. Want to add some scripting to your App?
Wow...now that is brilliant ChaosEngine
Is there an unplatform specific way?
not that I'm aware of.Originally Posted by bumfluff
"I saw a sign that said 'Drink Canada Dry', so I started"
-- Brendan Behan
Free Compiler: Visual C++ 2005 Express
If you program in C++, you need Boost. You should also know how to use the Standard Library (STL). Want to make games? After reading this, I don't like WxWidgets anymore. Want to add some scripting to your App?
How can I open google and then get it to search for something then close the window again?
well google has a well defined search interface, so you could simply build the search url and open that window.Originally Posted by bumfluff
for example, if you wanted to search for
object oriented
you'd build the following query URL
it's just a simple string manipulation. The only thing you need to watch out for is encoding. i.e. if you want to search for "object oriented" (note the quotes), you need to encode the quotes properlyCode:http://www.google.com/search?q=object+oriented
Code:http://www.google.com/search?q=%22object+oriented%22
"I saw a sign that said 'Drink Canada Dry', so I started"
-- Brendan Behan
Free Compiler: Visual C++ 2005 Express
If you program in C++, you need Boost. You should also know how to use the Standard Library (STL). Want to make games? After reading this, I don't like WxWidgets anymore. Want to add some scripting to your App?
Is it possible to then get it to open a certain hyperlink that appears after the search?
I wouldn't use system... use somethign more like Magos' suggestion.
Why? Consider this - with something like what Magos did, you know exactly what's going on. With system(), you're assuming your system has an interpreter, and the start command. Also that when you feed the URL to start, that start will find the default browser on the system, and that browser can take a URL on the command line.
You're assuming that not only does start and a browser exist, but all your settings are correct. On your system this may not be hard, but there's alot of spyware out there that changes your default settings. If your program's the first thing they pull up after some spy/malware changes their default browser, guess who's to blame
For things of this matter, you're probably better off using something like Perl or PHP, or if you REALLY wanna stick with C/C++, use it through CGI.
You're looking for a direct client-server connection that you probably can't get. But Perl and PHP's regex really help you pull out the results you want, and you can always write that to a local file for your C/C++ program to get. You may want to consider writing a relay in Perl, and have your C/C++ program connect to that through sockets...
Last edited by major_small; 05-10-2006 at 01:24 AM.
Join is in our Unofficial Cprog IRC channel
Server: irc.phoenixradio.org
Channel: #Tech
Team Cprog Folding@Home: Team #43476
Download it Here
Detailed Stats Here
More Detailed Stats
52 Members so far, are YOU a member?
Current team score: 1223226 (ranked 374 of 45152)
The CBoard team is doing better than 99.16% of the other teams
Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)
Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT