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);
}