Click here to Skip to main content
Licence 
First Posted 13 Aug 2002
Views 85,337
Bookmarked 30 times

Favorites MultiView

By | 28 Dec 2002 | Article
Favorites in multiple Views.

Sample Image

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)

  1. Build the Project
  2. Exit Visual Studio
  3. Log-on to the Internet
  4. Go to your favorite sites
  5. From the Internet Explorer menu option, select Favourites->Add (do not click on the Create in >> option). Save by clicking OK.
  6. Repeat steps 4-5 till you saved all you favorite sites
  7. 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.

//
// 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 no. of sites 
// on the Favourites menu option in this way
//
// Note : The that the file-wide Character Array
// if filled in this member function for later
// use in the process of retreiving 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 no. 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 retreive 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->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;
}
//
// 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 if the line for retreiving the site
    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 !!!!

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Barretto VN



India India

Member

Nothing to boast about

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralMultiview movie Pinmembermehmetned10:01 7 Nov '06  
GeneralRe: Multiview movie PinmemberBarretto VN23:16 7 Nov '06  
Generaldebug assertion failed Pinmemberhesterloli4:27 31 Jul '03  
GeneralRe: debug assertion failed PinmemberBarretto VN2:34 7 Aug '03  
GeneralAssert when compiled and run PinmemberCodeProjectSQ12:24 29 Dec '02  
GeneralRe: Assert when compiled and run PinmemberBarretto VN2:17 3 Jan '03  
GeneralRe: Assert when compiled and run PinmemberBarretto VN23:09 18 Jan '03  
GeneralImage didn't come up PinmemberMarc Clifton4:44 29 Dec '02  
GeneralRe: Image didn't come up PinmemberRavi Bhavnani6:27 29 Dec '02  
QuestionNo Binary? PinmemberSwinefeaster10:55 19 Aug '02  
Cmon do I really have to compile it to see if I like it? Wink | ;) Sounds interesting, but with no binary nor snapshot...
 
Cheers,
 
swine
 
Check out Aephid Photokeeper, the powerful digital
photo album solution at www.aephid.com.

GeneralGood Job!!!! PinmemberFrancisco Campos8:33 14 Aug '02  
GeneralResolving shortcuts PinsussAnonymous6:00 14 Aug '02  
GeneralFavorites folder PinsussAnonymous5:59 14 Aug '02  
GeneralNow THATS an article!! PinmemberAndreas Saurwein2:42 14 Aug '02  
GeneralRe: Now THATS an article!! PinsussJohn Simpsons4:24 14 Aug '02  
GeneralRe: Now THATS an article!! PinmemberAndreas Saurwein5:50 30 Dec '02  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120529.1 | Last Updated 29 Dec 2002
Article Copyright 2002 by Barretto VN
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid