What's New:
On request from Swinefeaster, I added an image and a demo version. A completely updated version allowing selection of Favorites is under testing.
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 Favorites folder in your Internet Explorer.
Sometime in 1997, I had downloaded a shareware software (don't remember it's name). The software had 8 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 which were probably made using 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 which I have learnt a lot over the years. As regards 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 managed to get what I wanted by trial and error methods.
I developed this project after seeing a similar project on some other site (???) which had 6 Views (3 columns and 2 rows) and surprisingly there were 6 sub-classes of CHTMLView
, one for each View.
Features
- Retrieve all Favorites sites
- Stop retrieval of individual sites
- Stop retrieval of all sites
- View individual sites in full-screen
How to Use: (the Application)
- Build the Project
- Exit Visual Studio
- Log-on to the Internet
- Go to your favorite sites
- From the Internet Explorer menu option, select Favourites->Add (do not click on the Create in >> option). Save by clicking OK.
- Repeat steps 4-5 till you saved all you favorite sites
- Close Internet Explorer (do not log-off the Internet)
To use when Logged-On to the Internet
- Start FavMV application from the project's Debug folder
- From the menu, select Favorites->Retreive
- To view individual sites in full-screen, first click on the site you want to view in full-screen and then from the menu, select View->Full-Screen.
- To open a site not in your favorites, select File->Open from the menu
To Use when Logged-Off from the Internet
- Start Internet Explorer
- From the menu option, select File->Work Offline
- Minimize Internet Explorer (do not close Internet Explorer)
- Start FavMV application from the project's Debug folder
- From the menu, select Favourites->Retreive
- To view individual sites in full-screen, 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 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.
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);
}
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;
if(strPath[strPath.GetLength() - 1] != _T('\\'))
strPath += _T('\\');
strPath2 = strPath;
strPath += "*.*";
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"))
{
::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);
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;
}
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".
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);
cv->NavigateTheURL(url);
cv->bURLRetreived = 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);
bURLRetreived=TRUE;
}
void CMyHTMLView::NavigateTheURL(CString url)
{
CString siteName = url.Mid(url.Find("//", 0)+2);
siteName = siteName.Left(siteName.Find("/",0));
m_SiteNameBar.SetWindowText(siteName);
m_WebBrowser.Navigate(url, NULL, NULL, NULL, NULL);
bURLRetreived = TRUE;
}
You can also view individual sites in full-screen, by first setting focus to the site you want to view in full-screen and then from the menu select View->Full-Screen.
Happy Surfing !!!!