CFileDialog的相關操作

2021-06-01 01:22:40 字數 2165 閱讀 7045

一般來講你不需要派生新的類,因為基類已經提供了常用的功能。而且在建立並等待對話方塊結束後你可以通過成員函式得到使用者在對話方塊中的選擇。

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:\test\test1.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:\windows\test.exe

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

(2)getfiletitle();取回test

(3)getfilename();取檔案全名:test.exe

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

開啟檔案

cfile file("c:\hello.txt",cfile::moderead);///唯讀方式開啟

///cfile::moderead可改為 cfile::modewrite(只寫),cfile::modereadwrite(讀寫),cfile::modecreate(新建)

例子:移動檔案指標

file.seek(100,cfile::begin);///從檔案頭開始往下移動100位元組

file.seek(-50,cfile::end);///從檔案末尾往上移動50位元組

file.seek(-30,cfile::current);///從當前位置往上移動30位元組

file.seektobegin();///移到檔案頭

file.seektoend();///移到檔案尾

讀寫檔案

讀檔案:

char buffer[1000];

file.read(buffer,1000);

寫檔案:

cstring string("這個世界只有偏執狂才能成功");

file.write(string,8);

關閉檔案

file.close();

jquery radio,select相關操作

1.獲取選中值,三種方法都可以 input radio checked val input type radio checked val input name rd checked val 2.設定第乙個radio為選中值 input radio first attr checked checked...

CFileDialog的用法簡介

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

對於CFileDialog的研究

cfiledialog 建構函式 cfiledialog bool bopenfiledialog,lpctstr lpszdefext null,lpctstr lpszfilename null,dword dwflags ofn hidereadonly ofn overwriteprompt...