📄 subject_34446.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 >= 1000<BR>#pragma once<BR>#endif // _msc_ver >= 1000<BR><BR>class cdirdialog<BR>{<BR>public:<BR> cdirdialog();<BR> virtual ~cdirdialog();<BR> int dobrowse ();<BR> cstring m_strpath;<BR> cstring m_strinitdir;<BR> cstring m_strtitle;<BR> int 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> lpmalloc pmalloc;<BR> if (shgetmalloc (&pmalloc)!= noerror)<BR> {<BR> return 0;<BR> }<BR><BR> browseinfo binfo;<BR> lpitemidlist pidl;<BR> zeromemory ( (pvoid) &binfo,sizeof (browseinfo));<BR><BR> if (!m_strinitdir.isempty ())<BR> {<BR> olechar olepath[max_path];<BR> ulong cheaten;<BR> ulong dwattributes;<BR> hresult hr;<BR> lpshellfolder pdesktopfolder;<BR> // // get a pointer to the desktop's ishellfolder interface. //<BR> if (succeeded(shgetdesktopfolder(&pdesktopfolder)))<BR> {<BR><BR> //<BR> // ishellfolder::parsedisplayname requires the file name be in unicode.<BR> //<BR> multibytetowidechar(cp_acp, mb_precomposed, m_strinitdir.getbuffer (max_path), -1,<BR> olepath, max_path);<BR><BR> m_strinitdir.releasebuffer (-1);<BR> //<BR> // convert the path to an itemidlist.<BR> //<BR> hr = pdesktopfolder->parsedisplayname(null,<BR> null,<BR> olepath,<BR> &cheaten,<BR> &pidl,<BR> &dwattributes);<BR> if (failed(hr))<BR> {<BR> pmalloc ->free (pidl);<BR> pmalloc ->release ();<BR> return 0;<BR> }<BR> binfo.pidlroot = pidl;<BR> }<BR> }<BR> binfo.hwndowner = null;<BR> binfo.pszdisplayname = m_strpath.getbuffer (max_path);<BR> binfo.lpsztitle = (m_strtitle.isempty()) ? "open":m_strtitle;<BR> binfo.ulflags = bif_returnfsancestors|bif_returnonlyfsdirs;<BR><BR><BR> if ((pidl = ::shbrowseforfolder (&binfo)) == null)<BR> {<BR> return 0;<BR> }<BR> m_strpath.releasebuffer ();<BR> m_iimageindex = binfo.iimage;<BR><BR> if (::shgetpathfromidlist(pidl,m_strpath.getbuffer (max_path)) == false)<BR> {<BR> pmalloc ->free (pidl);<BR> pmalloc ->release ();<BR> return 0;<BR> }<BR><BR> m_strpath.releasebuffer ();<BR><BR> pmalloc ->free (pidl);<BR> pmalloc ->release ();<BR> 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 + -