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

📄 subject_58205.htm

📁 vc
💻 HTM
字号:
<p>
序号:58205 发表者:小希 发表日期:2003-10-30 17:34:17
<br>主题:获取程序所在目录的问题
<br>内容:一个程序,想获取该程序所在目录,请问是不是使用GetCurrentDirectory()这个函数??我想获得这个程序所在目录,但是在程序的对话框中有一个&#34;浏览&#34;的得到任意一个文件的路径然后显示在对话框中的功能,只要我选择了任意一个文件的路径然后点击获取当前目录的按钮时,得到的总是任意这个文件的目录,而不是程序所在的目录,该怎么样才能得到程序所在的目录.目前我的代码如下:<BR>void CTestDlg::OnExplore() //浏览按钮的响应函数<BR>{<BR>&nbsp;&nbsp;&nbsp;&nbsp;// TODO: Add your control notification handler code here<BR>&nbsp;&nbsp;&nbsp;&nbsp;UpdateData(TRUE);<BR>&nbsp;&nbsp;&nbsp;&nbsp;CString OpenFile=&#34;All Files(*.*)|*.*|&#34;;<BR>&nbsp;&nbsp;&nbsp;&nbsp;CFileDialog dlg(TRUE, NULL, NULL,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;OFN_FILEMUSTEXIST| OFN_HIDEREADONLY, NULL, this);<BR>&nbsp;&nbsp;&nbsp;&nbsp;if(dlg.DoModal()==IDOK)<BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m_Path=dlg.GetPathName();<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;UpdateData(FALSE);<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>}<BR><BR>void CTestDlg::OnView() //显示当前目录按钮的响应函数<BR>{<BR>&nbsp;&nbsp;&nbsp;&nbsp;// TODO: Add your control notification handler code here<BR>&nbsp;&nbsp;&nbsp;&nbsp;UpdateData(TRUE);<BR>&nbsp;&nbsp;&nbsp;&nbsp;CString sFilePath;<BR>&nbsp;&nbsp;&nbsp;&nbsp;char buf[100];<BR>&nbsp;&nbsp;&nbsp;&nbsp;GetCurrentDirectory(100,buf);<BR>&nbsp;&nbsp;&nbsp;&nbsp;sFilePath=buf;<BR>&nbsp;&nbsp;&nbsp;&nbsp;AfxMessageBox(sFilePath);<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>
<font color=red>答案被接受</font><br>回复者:CDMA2000 回复日期:2003-10-30 17:38:53
<br>内容:GetModuleFileName<BR><BR>The GetModuleFileName function retrieves the full path and filename for the executable file containing the specified module. <BR><BR><BR>得到后将路径解析出来<BR><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>
回复者:小希 回复日期:2003-10-30 17:39:10
<br>内容:我想得到的是这个执行程序所在的目录,上面的界面是为这个问题做的一个test,因为实际使用中有&#34;浏览&#34;这个功能.加了这个功能得到的总是&#34;路径&#34;对话框中浏览的文件的目录,不是本身这个程序的目录.想问一个如果让一个程序得到自己本身所在的目录该怎么做?谢谢!
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:小希 回复日期:2003-10-30 17:40:31
<br>内容:谢谢,我去试试看
<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 + -