Displaying Multiple Views in IE

Click here for a larger image.

Environment: VC6 Windows 98


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.


  • 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])
HKEY hKey;
DWORD dwSize;

if(RegOpenKey(HKEY_CURRENT_USER, _T("Software\\Microsoft\\
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,
ExpandEnvironmentStrings(sz, szPath, MAX_PATH);
// 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)


int nCount = 0;
CString strPath(pszPath);
CString strPath2;
CString str;
int nPos;
int nEndPos;
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);
nEndPos = nStartPos;
if((wfd.dwFileAttributes & (FILE_ATTRIBUTE_DIRECTORY|
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

_T(""), buf,
strPath2 + str);

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)
astrFavorites.InsertAt(nPos, str);
} while(FindNextFile(h, &wfd));

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->bURLRetrieved = TRUE;


CRect rect;
rect.right += 10;
rect.bottom += 10;
MoveWindow(rect, TRUE);
m_wndStatusBar.SetPaneText(0, "", 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));

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


Download demo project - 12 KB

Download source - 34 Kb

More by Author

Must Read