Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: MFC
I wanted to load the browse dialog with previous selection.
on opening the browse dialog it should come with previous selection folder/file..
 
can any one help me regarding this.
Posted 16-Apr-13 21:06pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

fist of all you can use CFileDialog to do so.Smile | :)
for more information on same you may go throught following link of msdn.
CFileDialog[^]
Or better refer your msdn.
 
Now question remain about you need previous directory!!!.
To do so,
CFileDialog open by default CurrentDirectory when it is open.
Means before modal of your CFileDialog if you check
GetCurrentDirectory()
Function you will get one path same path refered by CFileDialog to open.
 
after that, in any case if you change the current directory you get updated path in CFileDialog.
CurrentDirectory can be change two way.
1)if you call SetCurrentDirectory.
2)And CFileDialog also changes selected path as current directory.
 
So your solution is that,
1)Never change currentDirectory
 
Or
 
2)Better Make on String Variable to store directory path and setDirectory before calling CFileDialog.
Wink | ;)
Hope it will work for you..
 
And Yes if you talking about Folder Tree browse dialog then there ,
Not possiblility about setting path.
Because it shows by default Desktop path as currentDirectory.
  Permalink  
v2
Comments
p.uday kishore at 17-Apr-13 2:28am
   
we created a custom browse dialog for that one side tree control and other list control we used.
now am saving the path also of the current selection.i need to load that into that tree control now...
Coder Block at 17-Apr-13 2:32am
   
Yup then there bit logic.
See you have path that currently selecty ok,
Now you need to set tree node programmically with selected folder that is,
After loading your FolderStruture on tree control(Customize one) just set the node of tree with previously selected folder.
p.uday kishore at 17-Apr-13 3:13am
   
ya am looking on that.not able to set the path to that shell tree control...
Coder Block at 17-Apr-13 3:25am
   
so best article for you is this 1,
perfect match of folder selection..
 
http://www.codeproject.com/search.aspx?q=Folder+browser+dialog&usfc=false&doctypeid=1
p.uday kishore at 17-Apr-13 5:30am
   
hey can we compare the node items so we can get that????
Coder Block at 17-Apr-13 5:37am
   
yes you can if you understand following code then your job is much simpler
 
// name - the name of the item that is searched for
// tree - a reference to the tree control
// hRoot - the handle to the item where the search begins
HTREEITEM FindItem(const CString& name, CTreeCtrl& tree, HTREEITEM hRoot)
{
// check whether the current item is the searched one
CString text = tree.GetItemText(hRoot);
if (text.Compare(name) == 0)
return hRoot;

// get a handle to the first child item
HTREEITEM hSub = tree.GetChildItem(hRoot);
// iterate as long a new item is found
while (hSub)
{
// check the children of the current item
HTREEITEM hFound = FindItem(name, tree, hSub);
if (hFound)
return hFound;

// get the next sibling of the current item
hSub = tree.GetNextSiblingItem(hSub);
}

// return NULL if nothing was found
return NULL;
}
HTREEITEM CTreeDemoDlg::FindItem(const CString& name, CTreeCtrl& tree)
{
HTREEITEM root = m_tree.GetRootItem();
while(root != NULL)
{
HTREEITEM hFound = FindItem(name, tree, root);
if (hFound)
return hFound;

root = tree.GetNextSiblingItem(root);
}

return NULL;
}
 

better undestand code and then used it.
I have alternartive too.With LParam and HParam.
But before that apply above one.
;)
 
But passing string whould be your searching value..
 
And one more its function orverwiding too.
May u notice.
p.uday kishore at 17-Apr-13 8:48am
   
i got this code and it is working fine now..
can u suggest me any optimization in this code further.because it is taking more time when a folder contains more files ...
 
///////////////
CString defaultPath(_T("My Computer"));
CFile read_object;
CFile cfile_object;
char pbufRead[MAX_PATH];
memset(pbufRead,'\0',MAX_PATH);
if (!read_object.Open(csDllPath,CFile::modeRead, &e)) {
if (cfile_object.Open(csDllPath,CFile::modeCreate|CFile::modeReadWrite,&e)) {
cfile_object.Write("My Computer",11);
cfile_object.Flush();
cfile_object.Close();
}
}
else {

read_object.Read(pbufRead, sizeof(pbufRead));
read_object.Close();
CString tStr(pbufRead);
defaultPath=tStr;
}
 
if (pbufRead[1]!=L':') {
HTREEITEM hRootTree=m_CtrlMfcShellTree.GetRootItem();
CString headerTxt=m_CtrlMfcShellTree.GetItemText(hRootTree);
HTREEITEM hNextItem;
HTREEITEM hChildItem = m_CtrlMfcShellTree.GetNextVisibleItem(hRootTree);
while (hChildItem != NULL) {
hNextItem = m_CtrlMfcShellTree.GetNextItem(hChildItem, TVGN_NEXT);
CString childLabelStr=m_CtrlMfcShellTree.GetItemText(hChildItem);
if (childLabelStr.CompareNoCase(defaultPath)==0)
break;
hChildItem = hNextItem;
}
m_CtrlMfcShellList.DisplayFolder(defaultPath);
m_CtrlMfcShellTree.Expand(hChildItem,TVE_EXPAND);
//m_CtrlMfcShellTree.SetFocus();
}
else {
//m_CtrlMfcShellTree.SelectPath(defaultPath);
m_CtrlMfcShellList.DisplayFolder(defaultPath);
}
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Try this:
folderBrowser.SelectedPath = "yourpath";
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 240
1 Kamal Rocks 184
2 CPallini 155
3 PIEBALDconsult 150
4 BillWoodruff 148
0 OriginalGriff 5,695
1 DamithSL 4,506
2 Maciej Los 4,007
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,180


Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 17 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100