Solved

Load Web URL

Posted on 2001-06-11
10
257 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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
 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
cat dog challenge 18 127
maxBlock challenge 30 142
Creating an alias to a directory so I can change the directory 'contents' by changing the alias 5 90
noX challenge 17 130
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
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…
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 video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

830 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