整理 CFileDialog基本操作

2021-09-30 07:32:31 字數 3902 閱讀 7553

//#include "stdafx.h"

#include "cmyfiledialog.h"

#ifdef _debug

#define new debug_new

#undef this_file

static char this_file = __file__;

#endif

/using namespace std;

int fnopenfiledlg();

int _tmain(int argc, tchar* ar**, tchar* envp)

else

return nretcode;

}int fnopenfiledlg()

printf("您選擇的路徑是:%s/n", dlg.getpathname());

delete ppathname;

return s_ok;}

讓使用者選擇檔案的儲存路徑和名稱

<2010_1223>

<2011_0105>

cfiledialog 開啟儲存xx檔案, **太相似, 做個實驗, 重構一下, 使**量降低.

比如一下工程中要用到大量的cfiledialog, **中充斥這大量類似的cfiledialog**.

這個重構工作還是值得的.

<2011_0108>

cfiledialog的重構完成, 呼叫時清爽多了.

//#include "stdafx.h"

#include "lsfiledialogprj.h"

#include "lsfiledialog.h"

#ifdef _debug

#define new debug_new

#undef this_file

static char this_file = __file__;

#endif

/using namespace std;

int testfiledailog();

int _tmain(int argc, tchar* ar**, tchar* envp)

else

getchar();

return nretcode;

}int testfiledailog()

clsfiledialog封裝了cfiledialog操作, 變化的部分都在clsfiledialog呼叫者那裡

<2013_0901>

今天將lsfiledialog用在unicode工程中, 編譯不過~

搞了乙個unicode版, 以前用 tchar 就好了.

因為以後的工程不會再用mbcs, 用到寬字元的地方, 直接用 l"xx"

lresult cviewpe::onpefileparse(wparam wparam, lparam lparam)

#if !defined(afx_lsfiledialog_h__51b8cd18_6b93_44c1_b9ed_6e785f4b0a92__included_)

#define afx_lsfiledialog_h__51b8cd18_6b93_44c1_b9ed_6e785f4b0a92__included_

#if _msc_ver > 1000

#pragma once

#endif // _msc_ver > 1000

// lsfiledialog.h : header file///

// clsfiledialog dialog

#define g_ls_file_dialog_buf_len_max 4096 /**< 訪問檔案的buffer深度 */

class clsfiledialog : public cobject

;//}

// microsoft visual c++ will insert additional declarations immediately before the previous line.

#endif // !defined(afx_lsfiledialog_h__51b8cd18_6b93_44c1_b9ed_6e785f4b0a92__included_)

// lsfiledialog.cpp : implementation file

//#include "stdafx.h"

#include "mfcfiledlghelper.h"

#ifdef _debug

#define new debug_new

#undef this_file

static char this_file = __file__;

#endif

/// clsfiledialog

implement_dynamic(clsfiledialog, cobject)

clsfiledialog::clsfiledialog()

clsfiledialog::~clsfiledialog()

}void clsfiledialog::settitle(const wchar_t * pctitle)

void clsfiledialog::setopentype(bool bopen)

void clsfiledialog::setinitialpath(const wchar_t * pcinitialpath)

wchar_t * clsfiledialog::getinitialpath()

void clsfiledialog::setdefaultext(const wchar_t * pcdefaultext)

void clsfiledialog::setdefaultfilename(const wchar_t * pcdefaultfilename)

void clsfiledialog::setfiletypefilter(const wchar_t * pcfiletypefilter)

wchar_t * clsfiledialog::gettitle()

bool clsfiledialog::getopentype()

wchar_t * clsfiledialog::getdefaultext()

wchar_t * clsfiledialog::getdefaultfilename()

wchar_t * clsfiledialog::getfiletypefilter()

dword clsfiledialog::getopenflag()

else

return dwrc;

}int clsfiledialog::usrdomodal()

m_strfilenameselect.empty();

m_pfiledlg = new cfiledialog(

getopentype(),

getdefaultext(),

getdefaultfilename(),

getopenflag(),

getfiletypefilter(),

null);

if(!m_pfiledlg)

return nrc;

m_pfiledlg->m_ofn.lpstrinitialdir = getinitialpath();

m_pfiledlg->m_ofn.lpstrtitle = gettitle();

pchar ppathname = new char[g_ls_file_dialog_buf_len_max];

if(ppathname)}}

else

}delete ppathname;

ppathname = null;

}return nrc;

}

VC中CFileDialog的基本操作

vc中,經常使用cfiledialog進行檔案操作。而且在建立並等待對話方塊結束後你可以通過成員函式得到使用者在對話方塊中的選擇。cfiledialog檔案選擇對話方塊的使用 首先構造乙個物件並提供相應的引數,其建構函式原型如下 cfiledialog cfiledialog bool bopenf...

如何使用CFileDialog

cfiledialog的語法 cfiledialog bool bopenfiledialog,lpctstr lpszdefext null,lpctstr lpszfilename null,dword dwflags ofn hidereadonly ofn overwriteprompt,l...

如何使用CFileDialog

cfiledialog建構函式如下 cfiledialog bool bopenfiledialog,lpctstr lpszdefext null,lpctstr lpszfilename null,dworddwflags ofn hidereadonly ofn overwriteprompt...