MFC開啟 儲存檔案對話方塊 CFileDialog

2021-05-25 02:08:11 字數 1584 閱讀 2119

mfc開啟/儲存檔案對話方塊:cfiledialog

2008-03-15 12:02

cfiledialog

檔案選擇對話方塊的使用:首先構造乙個物件並提供相應的引數,建構函式原型如下:

cfiledialog::cfiledialog( bool bopenfiledialog, lpctstr lpszdefext = null, lpctstr lpszfilename = null, dword dwflags = ofn_hidereadonly | ofn_overwriteprompt, lpctstr lpszfilter = null, cwnd* pparentwnd = null );

引數意義如下:

bopenfiledialog 為true則顯示開啟對話方塊,為false則顯示儲存對話檔案對話方塊。

lpszdefext 指定預設的副檔名。

lpszfilename 指定預設的檔名。

dwflags 指明一些特定風格。

lpszfilter 是最重要的乙個引數,它指明可供選擇的檔案型別和相應的副檔名。引數格式如:

"chart files (*.xlc)|*.xlc|worksheet files (*.xls)|*.xls|data files (*.xlc;*.xls)|*.xlc; *.xls|all files (*.*)|*.*||";檔案型別說明和副檔名間用 | 分隔,同種型別檔案的副檔名間可以用 ; 分割,每種檔案型別間用 | 分隔,末尾用 || 指明。

pparentwnd 為父視窗指標。

建立檔案對話方塊可以使用domodal(),在返回後可以利用下面的函式得到使用者選擇:

cstring cfiledialog::getpathname( ) 得到完整的檔名,包括目錄名和副檔名如:c: est est1.txt

cstring cfiledialog::getfilename( ) 得到完整的檔名,包括副檔名如:test1.txt

cstring cfiledialog::getextname( ) 得到完整的副檔名,如:txt

cstring cfiledialog::getfiletitle ( ) 得到完整的檔名,不包括目錄名和副檔名如:test1

position cfiledialog::getstartposition( ) 對於選擇了多個檔案的情況得到第乙個檔案位置。

cstring cfiledialog::getnextpathname( position& pos ) 對於選擇了多個檔案的情況得到下乙個檔案位置,並同時返回當前檔名。但必須已經呼叫過position cfiledialog::getstartposition( )來得到最初的position變數。

例如

假如選擇的檔案是c:windowstest.exe

則:

(1)getpathname();取檔名全稱,包括完整路徑。取回c:windowstest.exe

(2)getfiletitle();取檔案全名:test.exe

(3)getfilename();取回test

(4)getfileext();取副檔名exe

MFC 實現開啟檔案對話方塊 儲存檔案對話方塊

cfiledialog cfiledialog bool bopenfiledialog,lpctstr lpszdefext null,lpctstr lpszfilename null,dword dwflags ofn hidereadonly ofn overwriteprompt,lpct...

MFC開啟 儲存檔案對話方塊 CFileDialog

cfiledialog 檔案選擇對話方塊的使用 首先構造乙個物件並提供相應的引數,建構函式原型如下 cfiledialog cfiledialog bool bopenfiledialog,lpctstr lpszdefext null,lpctstr lpszfilename null,dword...

MFC 檔案開啟和儲存對話方塊

開啟影象檔案 cfiledialog picfiledlg true,null,null,ofn hidereadonly ofn overwriteprompt ofn allowmultiselect,jpg jpg jpg 位 件 bmp bmp null 如果需要開啟其他型別的檔案,只需要在...