Solved

Open a web page in default browser

Posted on 1998-08-26
5
473 Views
Last Modified: 2013-11-19
From within an MFC program, how do I send an "open this web page" command to the default web browser?  How would I send it to a specific browser (such as Netscape)?
0
Comment
Question by:DenMan
  • 3
  • 2
5 Comments
 
LVL 2

Accepted Solution

by:
milenvk earned 30 total points
ID: 1321324
Here's how to open the default browser with a specific url:

void StartDefaultBrowser(LPCSTR url)
{
// Get the default browser from the registry
char webBrowser[260];
LONG webBrowserLen = sizeof(webBrowser);
LONG  l = RegQueryValue(HKEY_CLASSES_ROOT, "HTTP\\shell\\open\\command", webBrowser, &webBrowserLen);
  if( l != ERROR_SUCCESS )
  {
    AfxMessageBox("Error starting the default web browser.", MB_OK | MB_ICONERROR);
  return;
  }

  CString browseCommand = CString(webBrowser) + " \"" + url + "\"";

  WinExec(browseCommand, SW_SHOWNORMAL);
}

To open Netscape in similar manner look in the registry under HKEY_LOCAL_MACHINE\Software\Netscape key and get the folder where Netscape is installed. The same is with Internet Explorer.
0
 

Author Comment

by:DenMan
ID: 1321325
The registry entry on the machine I'm using is
  "<path>\Netscape.exe -h "%1""

This seems to open the search page at netscape, with the URL being one of the parameters.  I found that if I remove the -h and %1, it works ok.

Is there a way to send a cookie to Netscape at the same time?  I have a program that logs into a site, and it would sure be nice if I didn't require the user to also log in when Netscape gets opened.
0
 
LVL 2

Expert Comment

by:milenvk
ID: 1321326
Yes I had the same problem with Netscape and I removed the "-h". Now everything runs fine - including IE.

You better put your last question in a question instead of in a comment.
0
 
LVL 2

Expert Comment

by:milenvk
ID: 1321327
What I mean is that I can't help you with the cookie problem, but if you put the question in a EE "Question" you'll get the attention of some experts in the field.
0
 

Author Comment

by:DenMan
ID: 1321328
Will do.  Thanks for the advice.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Whole sheet autoscrub still needed 19 44
substring method in java 1 79
format the code in java 6 72
countEvens challenge 2 59
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now