Download source files - 28 Kb
1 - Screen shot of the default favorites URLs loaded.
2 - Screen shot of another derived version.
3 - Screen shot of the About dialog derived version.
Introduction and Credits:
This control was inspired by the Hyperlink Static controls developed by others like, Chris Maunder, Paul De Lascia and PJ Naughter (Thanks guys!). The implementation of favorites was also inspired by Charles Petzold's Favorites.EXE . I am using some of his code in my implementation, the exact lines are in the favorite directory opening routines. I further took the idea and put it into a
CListBox derived version.
Also, I wish to say a very special thanks to Erik Funkenbusch for his help and the fixing reply to my posted request on CP's The Lounge titled: CListBox!? Thank you Erik! As well to all the other replies! You are all good people. Thanks!
One could ask why a hyperlink list box? Because sometimes you have more than one Hyperlink to add, and just adding many Static controls would be a mess. Also because there are often times when there are many people I would like to credit, list their web contacts, or add more than one link to of my own in desired places inside my applications.
It works like a standard list box; by selecting and then double click a hyperlink list item you are taken to the URL! Have fun surfin! It also sports a tooltip when you select an item where the string length is longer than the width of the list control! :)
It can be used in many different ways. A few examples are:
- It could be used inside an About dialog (see the example graphic above) that would show all your web based contact details such as an Email or a personal website URL.
- It can be used in the Credits dialog to show the credit details of people involved in the project.
How to use it
First add the header and source (.h & .cpp) files to your project. Then, in your dialog or any window that you produce with the resource editor in VC++ while using the ClassWizard (Ctrl+W), add an instance of your list control. In the source code manually change the declaration of the listbox to the desired class.
The above will automatically subclass the window to the desired class. If you look at the DDX lines you would see this:
void CMyFavouritesDlg::DoDataExchange(CDataExchange* pDX)
DDX_Control(pDX, IDC_LIST_FAVORITES, m_List);
The IDC_LIST_FAVORITES is mapped to the m_List which in turn is the CFavorList class instance! :)
In the accompanied demo project, I have shown 3 different ways (See screen shots) of how to use this control. The first demo (Screen shot 1) and default ( without deriving and overriding ) is that it opens your computer's Favorites directory and loads all the URL files with the extension *.url into itself (ListBox). The second demo (Screen shot 2) is when you click the "Another..." button, you will view the list of links that I have put into the list with different colors by overriding the supplied virtual functions. The third demo (Screen shot 3) is inside the About dialog in which I am inserting my web contacts (email & site).
virtual void PreSubclassWindow();
virtual HBRUSH CtlColor(CDC* pDC, UINT nCtlColor);
To produce your own customized URL's list box, you can simply derive using the
CFavorList class as a base and then override the above mentioned virtuals.
Override to add your own strings:
For example, if you want to add your own string data into the list, then you could override the derived CFavorList class' implementation of
PreSubclassWindow() function like this:
Override to have your desired colors for text or background:
For exmaple, if you want your list's Text color to be Black then you could do this:
HBRUSH Cxxxxxxx::CtlColor(CDC* pDC, UINT nCtlColor)
return (HBRUSH) backBrush;
And if you want the background color to be different, a Dark Green example, you'd have to just set the Back Brush inside the default constructor of your derived class like this:
Ideas to further enhance this control
- To add subdirectory level functionality. However, you may have noticed that I have put a function called
EnumerateFolders() inside the code, it is there for later. It is not currently supported. But I am looking forward to fixing it. Any help is appreciated for sure!
- Add multi leveled Parent->Child relations, something like a Tree control. Parents would be the Directory names and then the URL Files as children, using tabs spaces to forward them. This would serve good in case the control is fully used for the Favorites Loading and Formatting!
- Any thing you come up with! :)
Suggestions, Corrections, Comments, and any ideas for enhancements are most welcome. You can post them here or email them to me if you wish.