Thread: Opening A Webpage

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    545

    Opening A Webpage

    How would I get a C++ program to open a web page in IE or even better in the default browser?

  2. #2
    Registered User
    Join Date
    Nov 2005
    Posts
    545
    Ok just delete this...I'll use Javascript instead.

  3. #3
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    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.

  4. #4
    semi-colon generator ChaosEngine's Avatar
    Join Date
    Sep 2005
    Location
    Chch, NZ
    Posts
    597
    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?

  5. #5
    Registered User
    Join Date
    Nov 2005
    Posts
    545
    Wow...now that is brilliant ChaosEngine

    Is there an unplatform specific way?

  6. #6
    semi-colon generator ChaosEngine's Avatar
    Join Date
    Sep 2005
    Location
    Chch, NZ
    Posts
    597
    Quote Originally Posted by bumfluff
    Wow...now that is brilliant ChaosEngine

    Is there an unplatform specific way?
    not that I'm aware of.
    "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?

  7. #7
    Registered User
    Join Date
    Nov 2005
    Posts
    545
    How can I open google and then get it to search for something then close the window again?

  8. #8
    semi-colon generator ChaosEngine's Avatar
    Join Date
    Sep 2005
    Location
    Chch, NZ
    Posts
    597
    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.

    for example, if you wanted to search for
    object oriented
    you'd build the following query URL
    Code:
    http://www.google.com/search?q=object+oriented
    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 properly
    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?

  9. #9
    Registered User
    Join Date
    Nov 2005
    Posts
    545
    Is it possible to then get it to open a certain hyperlink that appears after the search?

  10. #10
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 15
    Last Post: 11-27-2007, 08:47 PM
  2. need help with file opening errors
    By lld4rkll in forum C++ Programming
    Replies: 6
    Last Post: 07-13-2006, 06:20 AM
  3. Opening a webpage with C++
    By zach0616 in forum C++ Programming
    Replies: 4
    Last Post: 04-25-2005, 07:33 PM
  4. Downloading a webpage onto the disk?
    By Edin in forum Windows Programming
    Replies: 3
    Last Post: 11-23-2004, 01:37 AM
  5. Opening a webpage
    By okinrus in forum Windows Programming
    Replies: 2
    Last Post: 08-09-2003, 02:41 AM