1.方法1
TCHAR pBuf[MAX_PATH]; //存放路径的变量 GetCurrentDirectory(MAX_PATH, pBuf); //获取程序的当前目录 _tcscat_s(pBuf, _T("\")); _tcscat_s(pBuf, AfxGetApp()->m_pszExeName); _tcscat_s(pBuf, _T(".exe")); //获取程序的全文件名
2.方法2
//函数返回应用程序所在的路径 CString ReturnPath() { CString sPath; GetModuleFileName(NULL, sPath.GetBufferSetLength(MAX_PATH + 1), MAX_PATH); sPath.ReleaseBuffer(); int nPos; nPos = sPath.ReverseFind(_T('\')); sPath = sPath.Left(nPos); return sPath; }
----------------------------------------------------------------------------------------
CFileDialog fileDlg(TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, _T("All Files(*.*)|*.*||")); if (fileDlg.DoModal() == IDOK){ m_strPath2 = fileDlg.GetPathName(); // 获取文件路径 SetDlgItemText(EDIT2, m_strPath2); m_strFileName2 = fileDlg.GetFileName(); // 获取文件名 }