|
<!--------------------------------------------------------------------------->
<!-- INTRODUCTION
The Code Project article submission template (HTML version)
Using this template will help us post your article sooner. To use, just
follow the 3 easy steps below:
1. Fill in the article description details
2. Add links to your images and downloads
3. Include the main article text
That's all there is to it! All formatting will be done by our submission
scripts and style sheets.
-->
<!--------------------------------------------------------------------------->
<!-- IGNORE THIS SECTION -->
<html>
<head>
<title>The Code Project</title>
<Style> BODY, P, TD { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10pt }
H2,H3,H4,H5 { color: #ff9900; font-weight: bold; }
H2 { font-size: 13pt; }
H3 { font-size: 12pt; }
H4 { font-size: 10pt; color: black; }
PRE { BACKGROUND-COLOR: #FBEDBB; FONT-FAMILY: "Courier New", Courier, mono; WHITE-SPACE: pre; }
CODE { COLOR: #990000; FONT-FAMILY: "Courier New", Courier, mono; }
</Style>
<link rel="stylesheet" type="text/css" href="http://www.codeproject.com/styles/global.css">
</head>
<body bgcolor="#ffffff" color="#000000">
<!--------------------------------------------------------------------------->
<!------------------------------- STEP 1 --------------------------->
<!-- Fill in the details (CodeProject will reformat this section for you) -->
<pre>
Title: CSelectDialog
Author: Hojjat Bohlooli
Email: <A href="mailto:hojjat@live.com Member">hojjat@live.com
Member</A> ID: 930616
Language: Visual C++
Platform: Windows 9x, NT, XP, Vista
Technology: MFC
Level: Intermediate
Description: A multi select files and folders browse window
Section C++
SubSection MFC - Browse dialogs
License: Free for non commercial uses.
</pre>
<!------------------------------- STEP 2 --------------------------->
<!-- Include download and sample image information. -->
<ul class="download">
<li>
<a href="SelectDialog_demo.zip">Download demo project - 134 Kb </a>
<li>
<a href="SelectDialog_src.zip">Download source - 3 Kb</a></li>
</ul>
<p><img src="SampleImage.jpg" alt="Sample Image"></p>
<!------------------------------- STEP 3 --------------------------->
<!-- Add the article text. Please use simple formatting (<h2>, <p> etc) -->
<h2>Introduction</h2>
<P><STRONG>What's a problem?</STRONG>
<br>
It's has probably happened for you that need
a dialog like CFileDialog (MFC) that let you to select some items together. I'm
not mean multi select file feature but multi select files and folders.
<br>
If you search over MSDN and internet for libraries that do that for you, maybe
the best things you would find are CFileDialog for selecting single or multiple
files and SHBrowseForFolder api for select a single folder.
<br>
So the problem is that you need a utility that make it possible to select every
browse able thing.
<br>
<STRONG>What should we do to overcome the problem?</STRONG> But if you want to
have a single class using it you can select a file or a folder or some files or
some folders or mixture of them. I searched for such utility but found nothing.
<br>
So I decided to provide it and the best solution that I found was changing
CFileDialog to do what I need.
<br>
<STRONG>Solution</STRONG>
<br>
CSelectDialog is a class that is inherited from CFileDialog and make it
possible for you to browse your computer or network and select mixture of files
and folders.
<br>
For convenience of me(as implementer) and users, I add a member of type
CStringArray to class to keep selected items after dialog returns IDOK.
<br>
<STRONG>Difference of CSelectDialog and CFileDialog</STRONG>
<br>
1 - User interface of them have some differences.( you can see it in sample
image in Vista )
<br>
2 - OnInitDone, OnFolderChange, OnFileNameOK and WndProc functions of
CFileDialog are overrode in CSelectDialog.
</P>
<h2>Using the Code</h2>
<P>
Use of <code>CSelectDialog</code> is similar to <code>CFileDialog</code>.
Simply define a variable of type <code>CSelectDialog</code> and <code>DoModal</code>
it. after user clicked OK button you can access full path of selected items via <code>
m_lstSelectedItems</code> member. a code snippet that does this work is
shown below :
</P>
<pre lang=c++>
CSelectDialog ofd(TRUE, _T("*.*"), NULL,
OFN_HIDEREADONLY | OFN_ALLOWMULTISELECT,
_T("All files and folders(*.*)|*.*||") );
if( ofd.DoModal() != IDOK )
return;
for( int i=0; i<ofd.m_SelectedItemList.GetCount(); i++ )
m_lstSelectedItems.AddString( ofd.m_SelectedItemList[i] );
</pre>
<P><STRONG>Some Notes:</STRONG>
<br>
1 - If you wand to disable multi select you should make change in CSelectDialog
constructor.
<br>
2 - If you want to hide a combobox and its label in below of select dialog you
should uncomment 2 below lines in OnInitDone function.
</P>
<pre lang=c++>
...
//HideControl(cmb13);
//HideControl(stc3);
...
</pre>
<P>
3 - For prevention of exception in xp sp3 you should comment all lines
containing <code>cmb13</code> in <code>OnInitDone</code> function.
</P>
<h2>Points of Interest</h2>
<p>
When I searching internet nobody provive such browse dialog with this feature.
</p>
<h2>History</h2>
<p>Version 1.0 July 2008 : It is the first version of SelectDialog
<!------------------------------- That's it! ---------------------------></p>
</body>
</html>
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.