Solved

Load Web URL

Posted on 2001-06-11
10
259 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
 Watch the Recording: Learning MySQL 5.7

MySQL 5.7 has a lot of new features. If you've dabbled with an older version of MySQL, it is definitely worth learning.

 
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

Do you have a plan for Continuity?

It's inevitable. People leave organizations creating a gap in your service. That's where Percona comes in.

See how Pepper.com relies on Percona to:
-Manage their database
-Guarantee data safety and protection
-Provide database expertise that is available for any situation

Question has a verified solution.

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

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.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

623 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