转载:仅为个人查询方便
VC获取当前程序文件的路径,文件名以及路径+文件名
1.方法1 char pBuf[MAX_PATH]; //存放路径的变量 GetCurrentDirectory(MAX_PATH,pBuf); //获取程序的当前目录 strcat(pBuf,"//"); strcat(pBuf,AfxGetApp()->m_pszExeName); strcat(pBuf,".exe"); //获取程序的全文件名 2.方法2 //函数返回应用程序所在的路径 CString CClientApp::ReturnPath() { CString sPath; GetModuleFileName(NULL,sPath.GetBufferSetLength(MAX_PATH+1),MAX_PATH); sPath.ReleaseBuffer (); int nPos; nPos=sPath.ReverseFind('//'); sPath=sPath.Left(nPos); return sPath; } |
、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、
CFileDialog dlg(TRUE)
CFileDialog dlg(TRUE);//<-这里用TRUE与FALSE有什么不同?
// TRUE是“打开”对话框
// FALSE是“另存为”对话框
int ret=dlg.DoModal();
if(ret==IDOK)
{
CString pathname=dlg.GetPathName(); //得到文件所在路径+文件名
CString filename=dlg.GetFileName(); //得到文件名
char tbuf[120];
sprintf(tbuf,"The %s file in %s is saved!",filename,pathname);
AfxMessageBox(tbuf);
}