文件对话框CFileDialog

文件选择对话框的使用:首先构造一个对象并提供相应的参数,构造函数原型如下:

  CFileDialog::CFileDialog( BOOLbOpenFileDialog, LPCTSTR lpszDefExt = NULL, LPCTSTRlpszFileName= NULL, DWORD dwFlags = OFN_HIDEREADONLY |OFN_OVERWRITEPROMPT, LPCTSTRlpszFilter = NULL, CWnd* pParentWnd = NULL );

  参数意义如下:

  bOpenFileDialogTRUE则显示打开对话框,为FALSE则显示保存对话文件对话框。

  lpszDefExt指定默认的文件扩展名。

  lpszFileName指定默认的文件名。

  dwFlags指明一些特定风格。

  lpszFilter是最重要的一个参数,它指明可供选择的文件类型和相应的扩展名。参数格式如:

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

  pParentWnd为父窗口指针。

dwFlags

  A set of bitflags you can use to initialize the dialog box. When the dialog box returns, itsets these flags to indicate the user's input. This member can be a combinationof the following flags.

 

  OFN_ALLOWMULTISELECT

  Specifiesthat the File Name list box allows multiple selections. If you also set theOFN_EXPLORER flag, the dialog box uses the Explorer-style user interface;otherwise, it uses the old-style user interface.

 

  If the userselects more than one file, thelpstrFile bufferreturns the path to the current directory followed by the file names of theselected files. ThenFileOffset member is the offset,in bytes or characters, to the first file name, and thenFileExtensionmember is not used. For Explorer-style dialog boxes, the directory and filename strings are NULL separated, with an extra NULL character after the lastfile name. This format enables the Explorer-style dialog boxes to return longfile names that include spaces. For old-style dialog boxes, the directory andfile name strings are separated by spaces and the function uses short filenames for file names with spaces. You can use theFindFirstFilefunction to convert between long and short file names.

 

  If youspecify a custom template for an old-style dialog box, the definition of theFile Name list box must contain the LBS_EXTENDEDSEL value.

 

  OFN_CREATEPROMPT

  If the userspecifies a file that does not exist, this flag causes the dialog box to promptthe user for permission to create the file. If the user chooses to create thefile, the dialog box closes and the function returns the specified name;otherwise, the dialog box remains open. If you use this flag with theOFN_ALLOWMULTISELECT flag, the dialog box allows the user to specify only onenonexistent file.

 

  OFN_DONTADDTORECENT

  Windows2000/XP: Prevents the system from adding a link to the selected file in thefile system directory that contains the user's most recently used documents. Toretrieve the location of this directory, call the SHGetSpecialFolderLocationfunction with the CSIDL_RECENT flag.

 

  OFN_ENABLEHOOK

  Enables thehook function specified in thelpfnHook member.

 

  OFN_ENABLEINCLUDENOTIFY

  Windows2000/XP: Causes the dialog box to send CDN_INCLUDEITEM notification messages toyourOFNHookProc hook procedure when the user opens afolder. The dialog box sends a notification for each item in the newly openedfolder. These messages enable you to control which items the dialog boxdisplays in the folder's item list.

 

  OFN_ENABLESIZING

  Windows2000/XP, Windows 98/Me: Enables the Explorer-style dialog box to be resizedusing either the mouse or the keyboard. By default, the Explorer-style Open andSave As dialog boxes allow the dialog box to be resized regardless of whetherthis flag is set. This flag is necessary only if you provide a hook procedureor custom template. The old-style dialog box does not permit resizing.

 

  OFN_ENABLETEMPLATE

  Indicatesthat thelpTemplateName member is a pointer to thename of a dialog template resource in the module identified by thehInstance member. If the OFN_EXPLORER flag is set, thesystem uses the specified template to create a dialog box that is a child ofthe default Explorer-style dialog box. If the OFN_EXPLORER flag is not set, thesystem uses the template to create an old-style dialog box that replaces thedefault dialog box.

 

  OFN_ENABLETEMPLATEHANDLE

  Indicatesthat thehInstance member identifies a data blockthat contains a preloaded dialog box template. The system ignoreslpTemplateName if this flag is specified. If theOFN_EXPLORER flag is set, the system uses the specified template to create a dialogbox that is a child of the default Explorer-style dialog box. If theOFN_EXPLORER flag is not set, the system uses the template to create anold-style dialog box that replaces the default dialog box.

 

  OFN_EXPLORER

  Indicatesthat any customizations made to the Open or Save As dialog box use the newExplorer-style customization methods. For more information, see Explorer-StyleHook Procedures and Explorer-Style Custom Templates.

 

  By default,the Open and Save As dialog boxes use the Explorer-style user interfaceregardless of whether this flag is set. This flag is necessary only if youprovide a hook procedure or custom template, or set the OFN_ALLOWMULTISELECTflag.

 

  If you wantthe old-style user interface, omit the OFN_EXPLORER flag and provide areplacement old-style template or hook procedure. If you want the old style butdo not need a custom template or hook procedure, simply provide a hookprocedure that always returns FALSE.

 

  OFN_EXTENSIONDIFFERENT

  Specifiesthat the user typed a file name extension that differs from the extensionspecified bylpstrDefExt. The function does not usethis flag if lpstrDefExt is NULL.

 

  OFN_FILEMUSTEXIST

  Specifiesthat the user can type only names of existing files in the File Name entryfield. If this flag is specified and the user enters an invalid name, thedialog box procedure displays a warning in a message box. If this flag isspecified, the OFN_PATHMUSTEXIST flag is also used. This flag can be used in anOpen dialog box. It cannot be used with a Save As dialog box.

 

  OFN_FORCESHOWHIDDEN

  Windows2000/XP: Forces the showing of system and hidden files, thus overriding theuser setting to show or not show hidden files. However, a file that is markedboth system and hidden is not shown.

 

  OFN_HIDEREADONLY

  Hides theRead Only check box.

 

  OFN_LONGNAMES

  Forold-style dialog boxes, this flag causes the dialog box to use long file names.If this flag is not specified, or if the OFN_ALLOWMULTISELECT flag is also set,old-style dialog boxes use short file names (8.3 format) for file names withspaces. Explorer-style dialog boxes ignore this flag and always display longfile names.

 

  OFN_NOCHANGEDIR

  Restores thecurrent directory to its original value if the user changed the directory whilesearching for files.

 

  Windows NT4.0/2000/XP: This flag is ineffective forGetOpenFileName.

 

  OFN_NODEREFERENCELINKS

  Directs thedialog box to return the path and file name of the selected shortcut (.LNK)file. If this value is not specified, the dialog box returns the path and filename of the file referenced by the shortcut.

 

  OFN_NOLONGNAMES

  Forold-style dialog boxes, this flag causes the dialog box to use short file names(8.3 format). Explorer-style dialog boxes ignore this flag and always displaylong file names.

 

  OFN_NONETWORKBUTTON

  Hides anddisables the Network button.

 

  OFN_NOREADONLYRETURN

  Specifiesthat the returned file does not have the Read Only check box selected and isnot in a write-protected directory.

 

  OFN_NOTESTFILECREATE

  Specifiesthat the file is not created before the dialog box is closed. This flag shouldbe specified if the application saves the file on a create-nonmodifynetwork share. When an application specifies this flag, the library does notcheck for write protection, a full disk, an open drive door, or network protection.Applications using this flag must perform file operations carefully, because afile cannot be reopened once it is closed.

 

  OFN_NOVALIDATE

  Specifiesthat the common dialog boxes allow invalid characters in the returned filename. Typically, the calling application uses a hook procedure that checks thefile name by using the FILEOKSTRING message. If the text box in the editcontrol is empty or contains nothing but spaces, the lists of files anddirectories are updated. If the text box in the edit control contains anythingelse,nFileOffset and nFileExtensionare set to values generated by parsing the text. No default extension is addedto the text, nor is text copied to the buffer specified bylpstrFileTitle.If the value specified by nFileOffset is less thanzero, the file name is invalid. Otherwise, the file name is valid, andnFileExtension and nFileOffsetcan be used as if the OFN_NOVALIDATE flag had not been specified.

 

  OFN_OVERWRITEPROMPT

  Causes theSave As dialog box to generate a message box if the selected file alreadyexists. The user must confirm whether to overwrite the file.

 

  OFN_PATHMUSTEXIST

  Specifiesthat the user can type only valid paths and file names. If this flag is usedand the user types an invalid path and file name in the File Name entry field,the dialog box function displays a warning in a message box.

 

  OFN_READONLY

  Causes theRead Only check box to be selected initially when the dialog box is created.This flag indicates the state of the Read Only check box when the dialog box isclosed.

 

  OFN_SHAREAWARE

  Specifiesthat if a call to theOpenFile function fails becauseof a network sharing violation, the error is ignored and the dialog box returnsthe selected file name. If this flag is not set, the dialog box notifies yourhook procedure when a network sharing violation occurs for the file namespecified by the user. If you set the OFN_EXPLORER flag, the dialog box sendsthe CDN_SHAREVIOLATION message to the hook procedure. If you do not setOFN_EXPLORER, the dialog box sends the SHAREVISTRING registered message to thehook procedure.

 

  OFN_SHOWHELP

  Causes thedialog box to display the Help button. ThehwndOwnermember must specify the window to receive the HELPMSGSTRING registered messagesthat the dialog box sends when the user clicks the Help button. AnExplorer-style dialog box sends a CDN_HELP notification message to your hookprocedure when the user clicks the Help button.

 

  OFN_USESHELLITEM

  Do not use.

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值