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

}

發佈了0 篇原創文章 · 獲贊 0 · 訪問量 7659
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章