Load Web URL

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)
LVL 1
tvanceplusAsked:
Who is Participating?
 
jkrCommented:
'ShellExecute()' does work for any URL - were you online when testing this?
0
 
SrinivasaRaoCommented:
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
 
ravi_pvkumarCommented:

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

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
MadYugoslavCommented:
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
 
tvanceplusAuthor Commented:
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
 
MadYugoslavCommented:
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
 
tvanceplusAuthor Commented:
http://teambse.com
http://www.builders-software.com

try these

if they work, post again
0
 
SrinivasaRaoCommented:
Have you troed one suggested by ravi_pvkumar. I think it will be working for you.
BSR
0
 
jizhangCommented:

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
 
Roshan DavisCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.