Solved

Load Web URL

Posted on 2001-06-11
10
252 Views
Last Modified: 2013-11-20
I need to load a web page programatically. I set up a dynamic menu sort of like a favorites for an application. I tried ShellExecute but it is only working for local web pages, it isn't finding urls (like www.hotmail.com). I tried OpenURL but the link to the documentation from the index in my msdn is broken for some reason, so I can't read the documentation. I tried using openurl through cinternetsession, but I couldn't figure how to make it work. Does anyone know a simple function like

 GotoInDefaultBrowser(CString url)
0
Comment
Question by:tvanceplus
  • 2
  • 2
  • 2
  • +4
10 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 50 total points
ID: 6179512
'ShellExecute()' does work for any URL - were you online when testing this?
0
 

Expert Comment

by:SrinivasaRao
ID: 6179944
Are you working with Document/view architecture?
If so and do not have problems in using CHtmlView you can use it.Read MSDN documentation for more details.
BSR
0
 

Expert Comment

by:ravi_pvkumar
ID: 6180110

Hi,

//// this program is to get the content of the Web page requested.

declare m_Out,m_host,  as member variable of EditBox with type as string.

OnQuery is ON_BN_CLICK

OnQuery()
{
    const CString http = "http://";
    UpdateData(TRUE);
    m_Out = "";
    UpdateData(FALSE);
    TryURL(http + m_host);
    TryURL(http + "www." + m_host);

}




TryURL(CString URL)
{
 
 CInternetSession session;
  m_Out += "Trying " + URL + "\r\n";
  UpdateData(FALSE);
  CInternetFile* file = NULL;
   try
   {
        //We know for sure this is an Internet file,
          //so the cast is safe
          file = (CInternetFile*) session.OpenURL(URL);
   }// end of try
     catch (CInternetException* pEx)
     {
          //if anything went wrong, just set file to NULL
          file = NULL;
          pEx->Delete();
     } // end of catch
     if (file)
     {
          m_Out += "Connection established. \r\n";
          CString line;
for (int i=0; i < 20 && file->ReadString(line);i++)
{
               m_Out += line + "\r\n";
}
          file->Close();
          delete file;
     }
     else
     {
          m_Out += "No server found there. \r\n";
     }
     m_Out += "------------------------\r\n";
     UpdateData(FALSE);


}


if you want page to be displayed then go for AppWizard and in last step take help of htmlview
then in the function OnInitialUpdate
use the function named :      
Navigate2(_T("http://www.microsoft.com/visualc/"),NULL,NULL);

you can chage the url and navigate dynamically with your program
0
 
LVL 2

Assisted Solution

by:MadYugoslav
MadYugoslav earned 50 total points
ID: 6180422
Be sure that URL You specified sutisfy URL rules.
Try to specify protocol for open URL for example:

ShellExecute(m_hWnd, "open", "http://www.hotmail.com", NULL, NULL, SW_SHOWNORMAL);

What mean before You call ShellExecute You correct You URL string to start with protocol name gor browsing:
http://, ftp://, gopher://, and so on.
0
 
LVL 1

Author Comment

by:tvanceplus
ID: 6189324
I've tried ShellExecute several times. It isn't working. I tried the CInternetSession thing that you guys posted. That didn't work either. I am connected on a DSL through a proxy server. Could that screw the process up somehow? I am desperate (raising points) This product went to beta testing last week. I had a routine that searches the directory system for iexplore.exe, but I would really like it if I could use the default browser.
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 2

Expert Comment

by:MadYugoslav
ID: 6189679
I must repeat my last posted comment.
If it doesn't work please post URL You want to load (just for checking my solution).
0
 
LVL 1

Author Comment

by:tvanceplus
ID: 6196862
http://teambse.com
http://www.builders-software.com

try these

if they work, post again
0
 

Expert Comment

by:SrinivasaRao
ID: 6197513
Have you troed one suggested by ravi_pvkumar. I think it will be working for you.
BSR
0
 
LVL 1

Expert Comment

by:jizhang
ID: 6202620

I think use ShellExecute(...,"open","http://..."...) should work,
if you have set  your default web browser in your system
(or set web file type in Windows-Explorer->View->options->File type)

You need to fill right m_hWnd, for example, if I want to access the
web site when I display About Box:

void CA07App::OnAppAbout()
{
     CAboutDlg aboutDlg;
     aboutDlg.DoModal();
     ShellExecute(AfxGetApp()->m_pMainWnd->m_hWnd, _T("open"),                  _T("http://www.builders-software.com"), NULL, NULL, SW_SHOWNORMAL);

}

where I use AfxGetApp()->m_pMainWnd->m_hWnd to get m_hWnd.
I use _T("..."), because I compiled with _UNICODE option.

Another way is use ShellExecute() to run a .exe (netscape or IE executable)
and fill parameters in 4th arg:

ShellExecute
(m_hWnd,"open","C:\\netscape\\program\\netscape.exe","http://my_prox//my_target//index.html",....)
in 4th arg, fill out with the URL string format you used to use when access outside
web page.



0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9484624
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Answered by : jkr, MadYugoslav (points to be split)

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Roshan Davis
EE Cleanup Volunteer
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

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

757 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

17 Experts available now in Live!

Get 1:1 Help Now