CFileDialog 参数及返回值

来源:互联网 发布:关于办理电信网络诈骗 编辑:程序博客网 时间:2024/05/16 04:36

CFileDialog::CFileDialog

CFileDialog( BOOL bOpenFileDialog, LPCTSTR lpszDefExt = NULL, LPCTSTR lpszFileName =

NULL, DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, LPCTSTR lpszFilter =

NULL, CWnd* pParentWnd = NULL );

BOOL bOpenFileDialog
该参数为指定true是Open,false是Save as 对话框。

LPCTSTR lpszDefExt
添加到没有扩展名文件上的扩展名

LPCTSTR lpszFileName
应该初始选定的文件名

DWORD dwFlags
自定义标志,当要进行多选的时候添加OFN_ALLOWMULTISELECT

LPCTSTR lpszFilter
File of type中的过滤参数
例如:
CString lpszFilter="位图(*.bmp)|*.bmp|/
   全部文件(*.*)|*.*||";  

 

"Chart Files (*.xlc)|*.xlc|Worksheet Files (*.xls)|*.xls|Data Files (*.xlc;*.xls)|*.xlc; *.xls|All Files (*.*)|*.*||";文件类型说明和扩展名间用 | 分隔,同种类型文件的扩展名间可以用 ; 分割,每种文件类型间用 | 分隔,末尾用 || 指明。

CWnd* pParentWnd
父窗口的指针。


CFileDialog::GetFileName 得到打开文件的名字

For example, GetFileName will return "TEXT.DAT" for the file C:/FILES/TEXT.DAT.


CFileDialog::GetFileTitle 得到打开文件的标题,不含扩展名。

For example, GetFileTitle will return "TEXT" for the file C:/FILES/TEXT.DAT.


CFileDialog::GetFileExt 得到打开文件的扩展名。

For example, if the name of the file entered is DATA.TXT, GetFileExt returns "TXT".


CFileDialog::GetPathName 得到打开文件的路径名

For example, GetPathName will return "C:/FILES/TEXT.DAT" for the file

C:/FILES/TEXT.DAT.

CFileDialog::GetStartPosition得到列表中第一个文件路径的位置。

该函数使用时候,构造函数中的dwFlags必须选定OFN_ALLOWMULTISELECT


CFileDialog::GetNextPathName根据选择的位置返回该文件的路径名

For example, GetNextPathName will return "C:/FILES/TEXT.DAT" for the file

C:/FILES/TEXT.DAT.


CFileDialog::OnShareViolation当用户发生共享时,该函数返回共享警告或提示。
一般系统会自动提示

virtual UINT OnShareViolation( LPCTSTR lpszPathName );

If you want to disable share violation checking, use the bitwise OR operator to combine

the flag OFN_SHAREAWARE with m_ofn.Flags.


CFileDialog::OnFileNameOK使得在对话框输入的文件名生效。
一般系统会自动提示

 

 

简单的打开文件对话框

CFileDialog hFileDlg(TRUE,NULL,NULL,OFN_FILEMUSTEXIST|OFN_PATHMUSTEXIST|OFN_READONLY,
TEXT("所有支持的图像文件 (*.jpg;*.gif;*.bmp;...)|*.jpg;*.gif;*.bmp|Tiff图像文件(*.tiff;*.tif)|*.tiff;*.tif||"),NULL);
hFileDlg.m_ofn.nFilterIndex=2;
hFileDlg.m_ofn.hwndOwner=m_hWnd;
hFileDlg.m_ofn.lStructSize=sizeof(OPENFILENAME);
hFileDlg.m_ofn.lpstrTitle=TEXT("打开图像文件.../0");
hFileDlg.m_ofn.nMaxFile=MAX_PATH;
if(hFileDlg.DoModal() == IDOK)
{
m_path=_T("");
m_path = hFileDlg.GetPathName();
AfxMessageBox(m_path);
}

 

///////////////////////////////////////另存为对话框

CString filename;//保存路径

//图像文件 (*.jpg;*.gif;*.bmp;...)|*.jpg;*.gif;*.bmp|所有文件(*.*;)|*.*||
   CFileDialog opendlg (FALSE,_T("*"),_T("1.jk"),OFN_OVERWRITEPROMPT, _T("所有文件(*.*;)|*.*||"),NULL);  
if (opendlg.DoModal()==IDOK)
{
   filename=opendlg.GetPathName();  
}
/////////
AfxMessageBox(filename);

 

 

感谢转载作者:http://hi.baidu.com/gootyking/blog/item/8586f82f8103d5e08b139926.html

原创粉丝点击