Displaying Multiple Views in IE



Click here for a larger image.

Environment: VC6 Windows 98

Introduction

This article demonstrates the technique of dynamically creating multiple Views at run-time and opening Web pages on the Views created. The number of views created depends on the list of Web pages saved at the root of the Favourites in your Internet Explorer.

Sometime in 1997, I downloaded some shareware (I don't remember its name); the software had eight views in which you could open sites. At that time, I was a Visual Basic developer and used to be fascinated by these software packages that were probably made with C++ (an alien language for me then), but now that I know a little about VC++, I thought why not try something of this sort and then, if possible, share the code with the Internet community, because of whom I have learnt a lot over the years. In regard to multiple views, I searched all over the MSDN CD (in VS6) and in frustration finally posted my question to a site named ..... and after 15 days got a reply from them, before which I had I managed to get what I wanted to achieve by the trial and error method.

I developed this project after seeing a similar project on this site; it had 6 views (3 columns and 2 rows) and surprisingly there were 6 views of CHTMLView, one for each column. I have tested opening 28 Web pages (4 columns by 7 rows) at a time without any problem.

Features

  • Retrieve all Favourite Sites
  • Stop retrieval of individual sites
  • Stop retrieval of all sites

How to Use the Application

  1. Build the Project.
  2. Exit Visual Studio.
  3. Log on to the Internet.
  4. Go to your favourite sites.
  5. From the Internet Explorer menu option, select Favourites, Add (do not click the Create in >> option).
  6. Save by clicking OK.
  7. Repeat Steps 4-5 until you save all you favourite sites.
  8. Close Internet Explorer (do not log off the Internet).

To use when logged on to the Internet

  1. Start the FavMV application from the Projects Debug folder.
  2. From the menu, select Favourites, Retrieve.
  3. To view individual sites in full-screen mode, first click on the site you want to view in full-screen and then from the menu select View, Full-Screen.
  4. To open a site not in your favourites, select File, Open from the menu.

To use when logged off from the Internet

  1. Start Internet Explorer.
  2. From the menu option, select File, Work Offline.
  3. Minimize Internet Explorer (do not close Internet Explorer).
  4. Start the FavMV application from the Projects Debug folder.
  5. From the menu, select Favourites, Retrieve.

To View in Full-Screen Mode

To view individual sites in full-screen mode, first click on the site you want to view in full-screen and then from the menu select View, Full-Screen.

About the Code

I have embedded the CWebBrowser2 ActiveX control inside the CHTMLView sub-class, which is of type CView and not CHtmlView, because I wanted to display the name of each site on the bar inside each View. I could have used CHtmlView instead.

//
// To start, we get the location of Favourites folder
// on the system from the Registry in this way
//
BOOL CMainFrame::getFavouriteskey(TCHAR szPath[MAX_PATH])
{
  TCHAR           sz[MAX_PATH];
  HKEY            hKey;
  DWORD           dwSize;

  if(RegOpenKey(HKEY_CURRENT_USER, _T("Software\\Microsoft\\
                Windows\\CurrentVersion\\Explorer\\
                User Shell Folders"), &hKey) != ERROR_SUCCESS)
  {
    TRACE0("Favorites folder not found\n");
    return FALSE;
  }
  dwSize = sizeof(sz);
  RegQueryValueEx(hKey, _T("Favorites"), NULL, NULL, (LPBYTE)sz,
                  &dwSize);
  ExpandEnvironmentStrings(sz, szPath, MAX_PATH);
  RegCloseKey(hKey);
}
//
// Using the returned folder path above, we find the count of the
// number of sites on the Favourites menu option in this way
//
// Note : The that the file-wide Character Array is filled in this
// member function for later use in the process of retrieving
// the sites
//
int CMainFrame::GetFavorites(LPCTSTR pszPath, int nStartPos ,
                             CStringArray* caFavourites)
{

  #define INTERNET_MAX_PATH_LENGTH 256

  int nCount = 0;
  CString         strPath(pszPath);
  CString         strPath2;
  CString         str;
  WIN32_FIND_DATA wfd;
  HANDLE          h;
  int             nPos;
  int             nEndPos;
  TCHAR           buf[INTERNET_MAX_PATH_LENGTH];
  CStringArray    astrFavorites;
  CStringArray    astrDirs;

  // make sure there's a trailing backslash
  if(strPath[strPath.GetLength() - 1] != _T('\\'))
    strPath += _T('\\');
  strPath2 = strPath;
  strPath += "*.*";

  // now scan the directory, first for .URL files and then for
  // subdirectories that may also contain .URL files

  h = FindFirstFile(strPath, &wfd);
  if(h != INVALID_HANDLE_VALUE)
  {
    nEndPos = nStartPos;
    do
    {
      if((wfd.dwFileAttributes & (FILE_ATTRIBUTE_DIRECTORY|
                                  FILE_ATTRIBUTE_HIDDEN|
                                  FILE_ATTRIBUTE_SYSTEM))==0)
      {
        str = wfd.cFileName;
        if(str.Right(4) == _T(".url"))
        {

          // an .URL file is formatted just like an .INI file,
          // so we can use GetPrivateProfileString() to get the
          // information we want
          ::GetPrivateProfileString(_T("InternetShortcut"),
                                    _T("URL"),
                                    _T(""), buf,
                                    INTERNET_MAX_PATH_LENGTH,
                                    strPath2 + str);

          caFavourites->Add(buf);
          str = str.Mid(0, str.GetLength()-4);
          str = str.Left(str.GetLength() - 4);

          // scan through the array and perform an insertion sort
          // to make sure the menu ends up in alphabetic order
          for(nPos = nStartPos ; nPos < nEndPos ; ++nPos)
         {
            if(str.CompareNoCase(astrFavorites[nPos]) < 0)
              break;
          }
          astrFavorites.InsertAt(nPos, str);
          ++nEndPos;
          nCount++;
        }
      }
    } while(FindNextFile(h, &wfd));
    FindClose(h);
  }

  return nCount;
}
//
// We now create Views depending on the number of sites
// as returned above, in this way
//
void CMainFrame::CreateViews(int nRows, int nCols,
                             CCreateContext* pContext)
{
  int i ,j;
  int iIndex = 0;
  m_Splitter.CreateStatic(this, nRows,nCols);
  for( i = 0 ; i <= nRows-1;i++)
    for( j = 0; j <= nCols-1 ; j++)
      m_Splitter.CreateView(i,j, RUNTIME_CLASS(CMyHTMLView),
                                 CSize(0,0), pContext);

}

// having created the View we wait for the user to click
// on the menu option "Retrieve"
//
// we now retrieve each of the sites into the View using the
// character array filled in in the member function
// GetFavorites above
//
void CMainFrame::OnRetrieve()
{
  int i,j;
  int nCols = m_Splitter.GetColumnCount();
  int nRows = m_Splitter.GetRowCount();
  int iIndex = 0;
  for( i = 0 ; i <= nRows-1;i++)
  {
    for( j = 0; j <= nCols-1 ; j++)
    {
      CString url = caFavourites.GetAt(iIndex);
      CString siteName = url.Mid(url.Find("//", 0)+2);
      siteName = siteName.Left(siteName.Find("/",0));
      m_wndStatusBar.SetPaneText(0, siteName, TRUE);
      CMyHTMLView* cv = (CMyHTMLView*)m_Splitter.GetPane(i,j);
      // the URL is passed here to the respective
      // sub-class view CMyHTMLView to open the site
      cv->NavigateTheURL(url);
      cv->bURLRetrieved = TRUE;
      iIndex++;
      if(bStopAll)
        break;
    }
    if(bStopAll)
      break;

  }

  CRect rect;
  GetClientRect(&rect);
  rect.right += 10;
  rect.bottom += 10;
  MoveWindow(rect, TRUE);
  m_wndStatusBar.SetPaneText(0, "", TRUE);
  bURLRetrieved=TRUE;
}
//
// The method for displaying sites is quite simple as can be
// seen below in the sub-class CHTMLView
// (all the above is in the Mainframe CMainFrame)
//
void CMyHTMLView::NavigateTheURL(CString url)
{

  CString siteName = url.Mid(url.Find("//", 0)+2);
  siteName = siteName.Left(siteName.Find("/",0));

  m_SiteNameBar.SetWindowText(siteName);
  // below is the line for retrieving the site
  m_WebBrowser.Navigate(url, NULL, NULL, NULL, NULL);
  bURLRetrieved = TRUE;
}

Downloads

Download demo project - 12 KB
Download source - 34 Kb


Comments

  • Is it possible, to exchnage contents of two WebBrowser controls?

    Posted by Legacy on 02/28/2003 12:00am

    Originally posted by: Christian Schildt

    Hi,

    I was looking for a solution of a problem and found your article. Good stuff. Maybe, you can give me some advice?

    I have written an add-in for IE (so called SmartViewers) that extends it with thumb nails functionality. It is a bar left of the IE client area with a number of small browser windows. The links can be dropped into these windows, and the contents is shown zoomed out. Each nail window can be swapped with the main browser. See

    http://schildt.netfirms.com/smartviewers.jpg

    I could not find a better solution for exchanging the contents of two WebBrowsers than simple re-navigation in each of them to URLs of the other. It would be great if the interface IWebBrowser2 had a method like set_Document(IDispatch*).

    Any help will be appriciated.

    Thanks

    Reply
  • Multiple Views in IE

    Posted by Legacy on 02/19/2003 12:00am

    Originally posted by: Arun

    Thus is quite goood....

    Reply
  • good

    Posted by Legacy on 02/17/2003 12:00am

    Originally posted by: feng

    see it very good.
    

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • On-demand Event Event Date: September 10, 2014 Modern mobile applications connect systems-of-engagement (mobile apps) with systems-of-record (traditional IT) to deliver new and innovative business value. But the lifecycle for development of mobile apps is also new and different. Emerging trends in mobile development call for faster delivery of incremental features, coupled with feedback from the users of the app "in the wild." This loop of continuous delivery and continuous feedback is how the best mobile …

  • As mobile devices have pushed their way into the enterprise, they have brought cloud apps along with them. This app explosion means account passwords are multiplying, which exposes corporate data and leads to help desk calls from frustrated users. This paper will discover how IT can improve user productivity, gain visibility and control over SaaS and mobile apps, and stop password sprawl. Download this white paper to learn: How you can leverage your existing AD to manage app access. Key capabilities to …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds