Sky Software Homepage LogicNP Software Knowledge Base And FAQ

 
Contact Product Support    SearchSearch      Subscribe to the RSS feed for this forum

ARTICLE: Creating a Windows Explorer clone with complete shell browsing GUI in your Visual C++ MFC application with Shell MegaPack ActiveX

 
Subscribe to the RSS feed for this forum  Forum Index -> Announcements
View previous topic :: View next topic  
Author Message
Support



Joined: 18 Jul 2005
Posts: 731

Posted: Mon Dec 01, 2008 10:33 am    Post subject: ARTICLE: Creating a Windows Explorer clone with complete shell browsing GUI in your Visual C++ MFC application with Shell MegaPack ActiveX

Original Article : http://www.ssware.com/articles/creating-explorer-clone-in-visualc++-mfc.htm

Introduction
Any developer who has ever wanted to provide file/folder browsing or file-selection functionality in his own application knows the utter lack of simple, extensible and customizable MFC components for this purpose.

Even as simple a task such as letting the user select a folder has to be accomplished by using complex shell programming APIs like SHBrowseForFolder. And all you get after all this is exactly the ability to let a user select a folder. The disadvantages of this approach, apart from the fact that it is very inflexible and non-customizable, is that this approach shows a modal dialog to the user, meaning the user has to deal with the dialog before moving on - either select the folder or cancel the operation.

Another option is to use the 'common dialogs' - the MFC CFileDialog class - which is almost as inflexible and narrow-minded in its goals and features. Sure it can be extended to add more controls, but only after you have spent 20 hours wrestling with subclassing and hooks and WindowProc.

To do away with the modal madness, you can a listbox and combobox in your own own dialog and use an API like the DlgDirList to list all drives, directories or files. All you get with these APIis is a textual list of filenames. Compare this to Windows Explorer which shows the entire shell's namespace including filesystem items and virtual items like Control Panel, Network Neighborhood etc in all their glory - with pretty icons, a hierarchical display of folders, Thumbnail or Details or Group Views, infotips, dragdrop, context menus, etc.

And with Shell MegaPack, you can get all this in your application. If you want drop-in Windows Explorer shell browsing functionality in your own application, with all features of Windows Explorer's features, along with the advanced behavior control and customization, and you want all of this with minimal time and effort, then Shell MegaPack is the way to go.

Inserting the controls in your dialog.
To insert the ActiveX controls in your MFC project, right click on the dialog at design time and select 'Insert ActiveX Control..'. In the dialog box that comes up, select 'LogicNP Software FolderView ActiveX Control" and click 'OK'. Repeat this procedure for FileView and ShComboBox. Now that all three controls are on your dialog, position and size the controls as per your needs and give them the desired IDs.

Next, we will add variables for all the three controls. To do so, right-click on the FileView control at design-time and select 'ClassWizard..'. Select the 'Member Variables' tab, select the ID for the FileView control in the 'Control IDs' listbox and click 'Add Variable..'. At this stage, Visual C++ will ask whether it should generate wrapper classes for the control. Click 'OK' and give the control the desired variable name and click 'OK again'. Repeat this step for the other two controls as well.

Setting properties
All three controls can be fully customized at design-time. To set properties, right click on the controls at design time and select 'LogicNP Software FolderView ActiveX Control Object' --> 'Properties..'. This will bring up the property pages from where you can customize the controls as per your needs. You can change the appearance and colors, set filtering modes (hide virtual items, hide hidden items, show folders), set the starting folder, set whether context menus, infotips, etc are shown and whether dragdrop is allowed. Almost every aspect of the controls can be customized at design time in this way.

Linking the controls together
Linking the three controls with each other enables them to synchronize automatically with each other. For example, if a new folder is selected in FolderView, FileView will automatically update itself to show the contents of that folder. Linking can be done in just 2 lines of code :

m_shCmbBox.SetFolderView((LPDISPATCH)m_fldrVw.GetControlUnknown());
m_fldrVw.SetFileView((LPDISPATCH)m_fileVw.GetControlUnknown());

Event Handling and behavior control
The controls come with a large number events which are fired when certain things occur, such as when the current folder has changed or an item has been clicked or double-clicked or selected or checked. The other use of events is to give you the opportunity to do advanced customization. For example, you might want to allow the display of context menus for one item but not another, or allow dropping of files on some particular folders or disallow execution of some files. Simply setting Cancel = True in the proper event allows you to accomplish this.

To handle an event, right click on the control at design time and select the 'Events..' menu item. In the dialog that comes up, select the appropriate event and click 'Add and Edit'. For example, to prevent display of context menus for folders, handle the OnItemRightClick event of FileView and use the following code :

CListItem i;
i.AttachDispatch(Item,FALSE);
if(i.GetAttributes(FOLDER) & FOLDER)
*Cancel=TRUE;


Advanced customization
The controls allow you to replace or extend the default attributes of items. You can change the display names (text) of files and folders ( for example, prefix an asterisk(*) before all files ), change the default icons shown for files and folders, add, remove or modify items from the context menu of files and folders, add custom columns in Details View. You can even add your own custom items to the controls. With this feature, you can recreate an entire shell namespace extension within your own application with minimal effort.

Conclusion
A Windows Explorer like shell browsing UI is required in many applications, yet there is no simple way to add such functionality in your application without spending countless hours for the most basic functionality. If you desire even a little semblance to the explorer UI and a little customization, then the corresponding time required grows exponentially. Shell MegaPack brings a drop-in shell browsing UI to your app within minutes and shields you from all the complexities and pains and the modal madness discussed above. Just the gains in terms of the time saved is more than worth it.
Back to top
Display posts from previous:   
Forum Index -> Announcements All times are GMT
Page 1 of 1

 
Jump to:  


Powered by phpBB © 2001, 2005 phpBB Group