How would I get a C++ program to open a web page in IE or even better in the default browser?
Printable View
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;
}
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");
Wow...now that is brilliant ChaosEngine
Is there an unplatform specific way?
not that I'm aware of.Quote:
Originally Posted by bumfluff
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.Quote:
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
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...