MFC中獲取檔名及路徑實現方法

2021-05-21 15:08:01 字數 3518 閱讀 3485

一、

利用cfiledialog類  

如下  

cstring   path;  

cfiledialog   dlg(true,null,"*.*");  

if   (dlg.domodal()==idok)

二、我用的是現成的類的方法  

//dirdialog.h  

//   dirdialog.h:   inte***ce   for   the   cdirdialog   class.  

//  

#if   !defined(afx_dirdialog_h__62ffac92_1dee_11d1_b87a_0060979cdf6d__included_)  

#define   afx_dirdialog_h__62ffac92_1dee_11d1_b87a_0060979cdf6d__included_  

#if   _msc_ver   >=   1000  

#pragma   once  

#endif   //   _msc_ver   >=   1000  

class   cdirdialog  

;  

static   int   __stdcall   cdirdialog::browsectrlcallback(hwnd   hwnd,   uint   umsg,   lparam   lparam,   lparam   lpdata);  

};  

#endif   //   !defined(afx_dirdialog_h__62ffac92_1dee_11d1_b87a_0060979cdf6d__included_)

三、//dirdialog.cpp  

///  

//   dirdialog.cpp:   implementation   of   the   cdirdialog   class.  

//  

#include   "stdafx.h"  

#include   "dirdialog.h"  

#include   "shlobj.h"  

#ifdef   _debug  

#undef   this_file  

static   char   this_file=__file__;  

#define   new   debug_new  

#endif  

//   callback   function   called   by   shbrowseforfolder's   browse   control  

//   after   initialization   and   when   selection   changes  

int   __stdcall   cdirdialog::browsectrlcallback(hwnd   hwnd,   uint   umsg,   lparam   lparam,   lparam   lpdata)  

else   if(   umsg   ==   bffm_selchanged   )  

return   0;  

}  

//  

//   construction/destruction  

//  

cdirdialog::cdirdialog()  

cdirdialog::~cdirdialog()  

bool   cdirdialog::dobrowse(cwnd   *pwndparent)  

lpmalloc   pmalloc;  

if   (shgetmalloc   (&pmalloc)!=   noerror)  

return   false;  

browseinfo   binfo;  

lpitemidlist   pidl;  

zeromemory   (   (pvoid)   &binfo,sizeof   (browseinfo));  

if   (!m_strinitdir.isempty   ())  

binfo.pidlroot   =   pidl;  

}  

}  

binfo.hwndowner   =   pwndparent   ==   null   ?   null   :   pwndparent->getsafehwnd();  

binfo.pszdisplayname   =   m_strpath.getbuffer   (max_path);  

binfo.lpsztitle   =   (m_strtitle.isempty())   ?   "open"   :   m_strtitle;  

binfo.ulflags   =   bif_returnfsancestors  

|   bif_returnonlyfsdirs  

|   (m_bstatus   ?   bif_statustext   :   0);  

binfo.lpfn   =   browsectrlcallback;     //   address   of   callback   function  

binfo.lparam   =   (lparam)this;             //   pass   address   of   object   to   callback   function  

if   ((pidl   =   ::shbrowseforfolder(&binfo))   ==   null)  

m_strpath.releasebuffer();  

m_iimageindex   =   binfo.iimage;  

if   (::shgetpathfromidlist(pidl,   m_strpath.getbuffer(max_path))   ==   false)  

m_strpath.releasebuffer();  

pmalloc   ->free(pidl);  

pmalloc   ->release();  

return   true;   }四、

五、browseinfo   bi   =   ;  

lpitemidlist   pidl;  

imalloc   *pmalloc   =   null;  

char   cszpath[max_path];  

bi.hwndowner   =   m_hwnd;  

bi.lpsztitle   =   "title";  

bi.ulflags   =   bif_returnonlyfsdirs;  

pidl   =   shbrowseforfolder(&bi);  

if   (pidl)  

if   (shgetmalloc(&pmalloc))   }六、

PHP 中獲取檔名及路徑

1.basename mnt img image01.jpg 函式 得到檔名 輸出結果為 image01.jpg.使用 basename uristring 我們可以得到乙個包含副檔名的檔名 如果不需要副檔名,也可以使用 basename uristring,extstring 過濾副檔名,僅僅返回...

PHP 中獲取檔名及路徑

1.basename mnt img image01.jpg 函式 得到檔名 輸出結果為 image01.jpg.使用 basename uristring 我們可以得到乙個包含副檔名的檔名 如果不需要副檔名,也可以使用 basename uristring,extstring 過濾副檔名,僅僅返回...

PHP 中獲取檔名及路徑

1.basename mnt img image01.jpg 函式 得到檔名 輸出結果為 image01.jpg.使用 basename uristring 我們可以得到乙個包含副檔名的檔名 如果不需要副檔名,也可以使用 basename uristring,extstring 過濾副檔名,僅僅返回...