⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 subject_34446.htm

📁 vc
💻 HTM
字号:
<p>
序号:34446 发表者:Guanglin 发表日期:2003-03-30 09:40:16
<br>主题:怎么指定初始目录?
<br>内容:有人用过弹出一个选择目录的对话框吗?怎么指定它的初始目录?
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
回复者:Justin Le 回复日期:2003-03-30 12:20:44
<br>内容:dlg.m_ofn.lpstrInitialDir="d:\\"; 
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:Guanglin 回复日期:2003-03-30 19:14:56
<br>内容:是选择目录的对话框,用SHBrowseForFolder做的:)<BR>不是CFileDialog,似乎没这个方法。
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:Justin Le 回复日期:2003-03-30 23:59:17
<br>内容:用BIF_RETURNONLYFSDIRS 
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:Justin Le 回复日期:2003-03-31 00:03:54
<br>内容:class to select directory<BR><BR>cdirdialog : this class encapsulates the shbrowseforfolder api. you can use this class to browse for folders. set the initial directory to start from using m_strinitdir. if you dont set this, it will start from desktop. <BR><BR>then call dobrowse (). if it returns true, you can see the m_strpath for the selected directory. if it returns false, user has dismissed the dialog with a cancel or there was some problem retrieving the folder. i have not put in any error code. if, somebody wants to they are welcome to do it. <BR><BR><BR>////////////////////////////////////////////////////////////////////////<BR>// dirdialog.h: interface for the cdirdialog class.<BR>//<BR>//////////////////////////////////////////////////////////////////////<BR><BR>#if<BR>!defined(afx_dirdialog_h__62ffac92_1dee_11d1_b87a_0060979cdf6d__included_)<BR>#define afx_dirdialog_h__62ffac92_1dee_11d1_b87a_0060979cdf6d__included_<BR><BR>#if _msc_ver &gt;= 1000<BR>#pragma once<BR>#endif // _msc_ver &gt;= 1000<BR><BR>class cdirdialog<BR>{<BR>public:<BR>&nbsp;&nbsp;&nbsp;&nbsp; cdirdialog();<BR>&nbsp;&nbsp;&nbsp;&nbsp; virtual ~cdirdialog();<BR>&nbsp;&nbsp;&nbsp;&nbsp; int dobrowse ();<BR>&nbsp;&nbsp;&nbsp;&nbsp; cstring m_strpath;<BR>&nbsp;&nbsp;&nbsp;&nbsp; cstring m_strinitdir;<BR>&nbsp;&nbsp;&nbsp;&nbsp; cstring m_strtitle;<BR>&nbsp;&nbsp;&nbsp;&nbsp; int&nbsp;&nbsp;m_iimageindex;<BR><BR>};<BR><BR>#endif //<BR>!defined(afx_dirdialog_h__62ffac92_1dee_11d1_b87a_0060979cdf6d__included_)<BR><BR><BR>///////////////////////////////////////////////////////////////////////////<BR>// dirdialog.cpp: implementation of the cdirdialog class.<BR>//<BR>//////////////////////////////////////////////////////////////////////<BR><BR>#include "stdafx.h"<BR>#include "dirdialog.h"<BR>#include "shlobj.h"<BR>#ifdef _debug<BR>#undef this_file<BR>static char this_file[]=__file__;<BR>#define new debug_new<BR>#endif<BR><BR>//////////////////////////////////////////////////////////////////////<BR>// construction/destruction<BR>//////////////////////////////////////////////////////////////////////<BR><BR>cdirdialog::cdirdialog()<BR>{////////////////////////////////////////////<BR><BR>}<BR><BR>cdirdialog::~cdirdialog()<BR>{///////////////////////////////////////////<BR><BR>}<BR><BR>int cdirdialog::dobrowse ()<BR>{/////////////////////////////////////////<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;lpmalloc pmalloc;<BR>&nbsp;&nbsp;&nbsp;&nbsp;if (shgetmalloc (&amp;pmalloc)!= noerror)<BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return 0;<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;browseinfo binfo;<BR>&nbsp;&nbsp;&nbsp;&nbsp;lpitemidlist pidl;<BR>&nbsp;&nbsp;&nbsp;&nbsp;zeromemory ( (pvoid) &amp;binfo,sizeof (browseinfo));<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp; if (!m_strinitdir.isempty ())<BR>&nbsp;&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;olechar&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; olepath[max_path];<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ulong&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cheaten;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ulong&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dwattributes;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hresult&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; hr;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lpshellfolder pdesktopfolder;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// // get a pointer to the desktop's ishellfolder interface. //<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (succeeded(shgetdesktopfolder(&amp;pdesktopfolder)))<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // ishellfolder::parsedisplayname requires the file name be in unicode.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; multibytetowidechar(cp_acp, mb_precomposed, m_strinitdir.getbuffer (max_path), -1,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;olepath, max_path);<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m_strinitdir.releasebuffer (-1);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // convert the path to an itemidlist.<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //<BR>&nbsp;&nbsp;&nbsp;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&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pmalloc -&gt;free (pidl);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pmalloc -&gt;release ();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return 0;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; binfo.pidlroot = pidl;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp; }<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;binfo.hwndowner = null;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;binfo.pszdisplayname = m_strpath.getbuffer (max_path);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;binfo.lpsztitle = (m_strtitle.isempty()) ? "open":m_strtitle;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;binfo.ulflags = bif_returnfsancestors|bif_returnonlyfsdirs;<BR><BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ((pidl = ::shbrowseforfolder (&amp;binfo)) == null)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return 0;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m_strpath.releasebuffer ();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m_iimageindex = binfo.iimage;<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (::shgetpathfromidlist(pidl,m_strpath.getbuffer (max_path)) == false)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pmalloc -&gt;free (pidl);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pmalloc -&gt;release ();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return 0;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;m_strpath.releasebuffer ();<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;pmalloc -&gt;free (pidl);<BR>&nbsp;&nbsp;&nbsp;&nbsp;pmalloc -&gt;release ();<BR>&nbsp;&nbsp;&nbsp;&nbsp; return 1;<BR>}<BR><BR>enhancement<BR>this enhancement was sent by lars klose. <BR><BR>i downloaded girish bharadwaj's wrapper class for shbrowseforfolder, cdirdialog, a few days ago. because it seems useful to me to set the selected folder to a default value other than 'desktop' when the dialog opens, i extended girish bharadwaj's implementation with a callback function that sets the selected folder when the dialog is initialized. it's set to the value stored in the new member variable m_strseldir or defaults to 'desktop' if m_strseldir was not set. the attached zip contains the changed files dirdialog.h and .cpp. <BR><BR>你可以下载<BR>http://www.csdn.net/dev/Visual%20C++/source%20code/Dialog/dirdlg.zip<BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:Guanglin 回复日期:2003-03-31 13:31:53
<br>内容:thx~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~very much!!!!
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -