CFileDialog簡單使用

2021-08-21 21:27:01 字數 1809 閱讀 5473

cfiledialog類封裝了windows常用的檔案對話方塊。常用的檔案對話方塊提供了一種簡單的與windows標準相一致的檔案開啟和檔案存檔對話方塊功能[1]。

一、簡單使用示例

1、引數指定構造檔案開啟對話方塊,其餘預設引數

cfiledialog dlg(true);                    // 構造檔案開啟對話方塊  

dlg.m_ofn.lpstrtitle = _t("open image"); // 檔案開啟對話方塊標題

if(idok != dlg.domodal()) // 判斷是否成功選中檔案

return;

cstring path = dlg.getpathname(); // 獲取檔案路徑

2、指定構造檔案開啟對話方塊

null); // 構造檔案開啟對話方塊

dlg.m_ofn.lpstrtitle = _t("open image"); // 檔案開啟對話方塊標題

if(idok != dlg.domodal()) // 判斷是否成功選中檔案

return;

cstring path = dlg.getpathname(); // 獲取檔案路徑二、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 為父視窗指標。

CFileDialog 使用簡單介紹

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

CFileDialog的使用方法簡單介紹

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

CFileDialog的使用方法簡單介紹

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