基于对话框的MFC保存数据问题
CStringsz="MyTypeFiles(*.txt)|*.txt|AllFile(*.*)|*.*||";SLorenzFileDlgdlg(true,".txt"...
CString sz="MyType Files (*.txt)|*.txt|All File(*.*)|*.*||";
SLorenzFileDlg dlg(true,".txt",NULL,OFN_FILEMUSTEXTST|OFN_HIDEREADONLY,sz,this);
if(IDOK==dlg.DoModal())
{
CString path=dlg.GetPathName() ;}//其中SLorenzFileDlg是我以CFileDialog为基类建立的类,可是便宜无法通过说
error C2065: 'OFN_FILEMUSTEXTST' : undeclared identifier
怎么回事? 展开
SLorenzFileDlg dlg(true,".txt",NULL,OFN_FILEMUSTEXTST|OFN_HIDEREADONLY,sz,this);
if(IDOK==dlg.DoModal())
{
CString path=dlg.GetPathName() ;}//其中SLorenzFileDlg是我以CFileDialog为基类建立的类,可是便宜无法通过说
error C2065: 'OFN_FILEMUSTEXTST' : undeclared identifier
怎么回事? 展开
4个回答
展开全部
你写错了,I 写成 T了!
应为OFN_FILEMUSTEXIST
写成OFN_FILEMUSTEXTST
explicit CFileDialog(
BOOL bOpenFileDialog,
LPCTSTR lpszDefExt = NULL,
LPCTSTR lpszFileName = NULL,
DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
LPCTSTR lpszFilter = NULL,
CWnd* pParentWnd = NULL,
DWORD dwSize = 0,
BOOL bVistaStyle = TRUE
);
OFN_ENABLEHOOK
OFN_ENABLEINCLUDENOTIFY
OFN_ENABLETEMPLATE
OFN_ENABLETEMPLATEHANDLE
OFN_EXPLORER
OFN_EXTENSIONDIFFERENT
OFN_HIDEREADONLY
OFN_LONGNAMES - effectively always on in Windows Vista
OFN_NOLONGNAMES - effectively always off in Windows Vista
OFN_NONETWORKBUTTON - effectively always on in Windows Vista
OFN_READONLY
OFN_SHOWHELP
lpstrTitlePointer to a string to be placed in the title bar of the dialog box. If this
member is NULL, the system uses the default title (that is, Save As or
Open).
FlagsA set of bit flags you can use to initialize the dialog box. When the dialog
box returns, it sets these flags to indicate the user's input. This member can
be a combination of the following flags.
OFN_ALLOWMULTISELECTSpecifies that the File Name list box allows multiple selections. If
you also set the OFN_EXPLORER flag, the dialog box uses the Explorer-style user
interface; otherwise, it uses the old-style user interface.
If the user selects more than one file, the lpstrFile buffer returns the path to the current
directory followed by the file names of the selected files. The nFileOffset member is the offset, in
bytes or characters, to the first file name, and the nFileExtension member is not used.
For Explorer-style dialog boxes, the directory and file name strings are NULL
separated, with an extra NULL character after the last file name. This format
enables the Explorer-style dialog boxes to return long file names that include
spaces. For old-style dialog boxes, the directory and file name strings are
separated by spaces and the function uses short file names for file names with
spaces. You can use the FindFirstFile function to convert between long
and short file names.
If you specify a custom template for an old-style dialog box, the definition of the File Name list box must contain the LBS_EXTENDEDSEL value.
OFN_CREATEPROMPTIf the user specifies a file that does not exist, this flag causes the
dialog box to prompt the user for permission to create the file. If the user
chooses to create the file, the dialog box closes and the function returns the
specified name; otherwise, the dialog box remains open. If you use this flag
with the OFN_ALLOWMULTISELECT flag, the dialog box allows the user to specify
only one nonexistent file.
OFN_DONTADDTORECENTWindows 2000/XP: Prevents the system from adding a link to the
selected file in the file system directory that contains the user's most
recently used documents. To retrieve the location of this directory, call the
SHGetSpecialFolderLocation
function with the CSIDL_RECENT flag.
OFN_ENABLEHOOKEnables the hook function specified in the lpfnHook member.
OFN_ENABLEINCLUDENOTIFYWindows 2000/XP: Causes the dialog box to send CDN_INCLUDEITEM
notification messages to your OFNHookProc hook
procedure when the user opens a folder. The dialog box sends a notification for
each item in the newly opened folder. These messages enable you to control which
items the dialog box displays in the folder's item list.
OFN_ENABLESIZINGWindows 2000/XP, Windows 98/Me: Enables the Explorer-style dialog box
to be resized using either the mouse or the keyboard. By default, the
Explorer-style Open and Save As dialog boxes allow the dialog box
to be resized regardless of whether this flag is set. This flag is necessary
only if you provide a hook procedure or custom template. The old-style dialog
box does not permit resizing.
OFN_ENABLETEMPLATEIndicates that the lpTemplateName member is a pointer to the name of
a dialog template resource in the module identified by the hInstance
member. If the OFN_EXPLORER flag is set, the system uses the specified template
to create a dialog box that is a child of the default Explorer-style dialog box.
If the OFN_EXPLORER flag is not set, the system uses the template to create an
old-style dialog box that replaces the default dialog box.
OFN_ENABLETEMPLATEHANDLEIndicates that the hInstance member identifies a data block that
contains a preloaded dialog box template. The system ignores lpTemplateName if this flag is
specified. If the OFN_EXPLORER flag is set, the system uses the specified
template to create a dialog box that is a child of the default Explorer-style
dialog box. If the OFN_EXPLORER flag is not set, the system uses the template to
create an old-style dialog box that replaces the default dialog box.
OFN_EXPLORERIndicates that any customizations made to the Open or Save As
dialog box use the new Explorer-style customization methods. For more
information, see Explorer-Style Hook
Procedures and Explorer-Style Custom
Templates.
By default, the Open and Save As dialog boxes use the
Explorer-style user interface regardless of whether this flag is set. This flag
is necessary only if you provide a hook procedure or custom template, or set the
OFN_ALLOWMULTISELECT flag.
If you want the old-style user interface, omit the OFN_EXPLORER flag and
provide a replacement old-style template or hook procedure. If you want the old
style but do not need a custom template or hook procedure, simply provide a hook
procedure that always returns FALSE.OFN_EXTENSIONDIFFERENTSpecifies that the user typed a file name extension that differs from the
extension specified by lpstrDefExt. The function does not use this flag if
lpstrDefExt is NULL.
OFN_FILEMUSTEXISTSpecifies that the user can type only names of existing files in the File
Name entry field. If this flag is specified and the user enters an invalid
name, the dialog box procedure displays a warning in a message box. If this flag
is specified, the OFN_PATHMUSTEXIST flag is also used. This flag can be used in
an Open dialog box. It cannot be used with a Save As dialog box.
OFN_FORCESHOWHIDDENWindows 2000/XP: Forces the showing of system and hidden files, thus
overriding the user setting to show or not show hidden files. However, a file
that is marked both system and hidden is not shown.
OFN_HIDEREADONLYHides the Read Only check box.
OFN_LONGNAMESFor old-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 with spaces. Explorer-style dialog boxes ignore this flag and always
display long file names.
OFN_NOCHANGEDIRRestores the current directory to its original value if the user changed the
directory while searching for files.
Windows NT 4.0/2000/XP: This flag is ineffective for GetOpenFileName.
OFN_NODEREFERENCELINKSDirects the dialog 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 file name of the file referenced by the shortcut.
OFN_NOLONGNAMESFor old-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
display long file names.
OFN_NONETWORKBUTTONHides and disables the Network button.
OFN_NOREADONLYRETURNSpecifies that the returned file does not have the Read Only check
box selected and is not in a write-protected directory.
OFN_NOTESTFILECREATESpecifies that the file is not created before the dialog box is closed. This
flag should be specified if the application saves the file on a create-nonmodify
network share. When an application specifies this flag, the library does not
check for write protection, a full disk, an open drive door, or network
protection. Applications using this flag must perform file operations carefully,
because a file cannot be reopened once it is closed.
OFN_NOVALIDATESpecifies that the common dialog boxes allow invalid characters in the
returned file name. Typically, the calling application uses a hook procedure
that checks the file name by using the FILEOKSTRING
message. If the text box in the edit control is empty or contains nothing but
spaces, the lists of files and directories are updated. If the text box in the
edit control contains anything else, nFileOffset and nFileExtension are set to values generated by parsing the
text. No default extension is added to the text, nor is text copied to the
buffer specified by lpstrFileTitle. If the value specified by nFileOffset is less than zero, the
file name is invalid. Otherwise, the file name is valid, and nFileExtension and nFileOffset can be used as if the
OFN_NOVALIDATE flag had not been specified.
OFN_OVERWRITEPROMPTCauses the Save As dialog box to generate a message box if the
selected file already exists. The user must confirm whether to overwrite the
file.
OFN_PATHMUSTEXISTSpecifies that the user can type only valid paths and file names. If this
flag is used and 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_READONLYCauses the Read 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 is closed.
OFN_SHAREAWARESpecifies that if a call to the OpenFile function
fails because of a network sharing violation, the error is ignored and the
dialog box returns the selected file name. If this flag is not set, the dialog
box notifies your hook procedure when a network sharing violation occurs for the
file name specified by the user. If you set the OFN_EXPLORER flag, the dialog
box sends the CDN_SHAREVIOLATION
message to the hook procedure. If you do not set OFN_EXPLORER, the dialog box
sends the SHAREVISTRING
registered message to the hook procedure.
OFN_SHOWHELPCauses the dialog box to display the Help button. The hwndOwner member must specify the
window to receive the HELPMSGSTRING
registered messages that the dialog box sends when the user clicks the
Help button. An Explorer-style dialog box sends a CDN_HELP
notification message to your hook procedure when the user clicks the Help
button.
OFN_USESHELLITEMDo not use.
应为OFN_FILEMUSTEXIST
写成OFN_FILEMUSTEXTST
explicit CFileDialog(
BOOL bOpenFileDialog,
LPCTSTR lpszDefExt = NULL,
LPCTSTR lpszFileName = NULL,
DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
LPCTSTR lpszFilter = NULL,
CWnd* pParentWnd = NULL,
DWORD dwSize = 0,
BOOL bVistaStyle = TRUE
);
OFN_ENABLEHOOK
OFN_ENABLEINCLUDENOTIFY
OFN_ENABLETEMPLATE
OFN_ENABLETEMPLATEHANDLE
OFN_EXPLORER
OFN_EXTENSIONDIFFERENT
OFN_HIDEREADONLY
OFN_LONGNAMES - effectively always on in Windows Vista
OFN_NOLONGNAMES - effectively always off in Windows Vista
OFN_NONETWORKBUTTON - effectively always on in Windows Vista
OFN_READONLY
OFN_SHOWHELP
lpstrTitlePointer to a string to be placed in the title bar of the dialog box. If this
member is NULL, the system uses the default title (that is, Save As or
Open).
FlagsA set of bit flags you can use to initialize the dialog box. When the dialog
box returns, it sets these flags to indicate the user's input. This member can
be a combination of the following flags.
OFN_ALLOWMULTISELECTSpecifies that the File Name list box allows multiple selections. If
you also set the OFN_EXPLORER flag, the dialog box uses the Explorer-style user
interface; otherwise, it uses the old-style user interface.
If the user selects more than one file, the lpstrFile buffer returns the path to the current
directory followed by the file names of the selected files. The nFileOffset member is the offset, in
bytes or characters, to the first file name, and the nFileExtension member is not used.
For Explorer-style dialog boxes, the directory and file name strings are NULL
separated, with an extra NULL character after the last file name. This format
enables the Explorer-style dialog boxes to return long file names that include
spaces. For old-style dialog boxes, the directory and file name strings are
separated by spaces and the function uses short file names for file names with
spaces. You can use the FindFirstFile function to convert between long
and short file names.
If you specify a custom template for an old-style dialog box, the definition of the File Name list box must contain the LBS_EXTENDEDSEL value.
OFN_CREATEPROMPTIf the user specifies a file that does not exist, this flag causes the
dialog box to prompt the user for permission to create the file. If the user
chooses to create the file, the dialog box closes and the function returns the
specified name; otherwise, the dialog box remains open. If you use this flag
with the OFN_ALLOWMULTISELECT flag, the dialog box allows the user to specify
only one nonexistent file.
OFN_DONTADDTORECENTWindows 2000/XP: Prevents the system from adding a link to the
selected file in the file system directory that contains the user's most
recently used documents. To retrieve the location of this directory, call the
SHGetSpecialFolderLocation
function with the CSIDL_RECENT flag.
OFN_ENABLEHOOKEnables the hook function specified in the lpfnHook member.
OFN_ENABLEINCLUDENOTIFYWindows 2000/XP: Causes the dialog box to send CDN_INCLUDEITEM
notification messages to your OFNHookProc hook
procedure when the user opens a folder. The dialog box sends a notification for
each item in the newly opened folder. These messages enable you to control which
items the dialog box displays in the folder's item list.
OFN_ENABLESIZINGWindows 2000/XP, Windows 98/Me: Enables the Explorer-style dialog box
to be resized using either the mouse or the keyboard. By default, the
Explorer-style Open and Save As dialog boxes allow the dialog box
to be resized regardless of whether this flag is set. This flag is necessary
only if you provide a hook procedure or custom template. The old-style dialog
box does not permit resizing.
OFN_ENABLETEMPLATEIndicates that the lpTemplateName member is a pointer to the name of
a dialog template resource in the module identified by the hInstance
member. If the OFN_EXPLORER flag is set, the system uses the specified template
to create a dialog box that is a child of the default Explorer-style dialog box.
If the OFN_EXPLORER flag is not set, the system uses the template to create an
old-style dialog box that replaces the default dialog box.
OFN_ENABLETEMPLATEHANDLEIndicates that the hInstance member identifies a data block that
contains a preloaded dialog box template. The system ignores lpTemplateName if this flag is
specified. If the OFN_EXPLORER flag is set, the system uses the specified
template to create a dialog box that is a child of the default Explorer-style
dialog box. If the OFN_EXPLORER flag is not set, the system uses the template to
create an old-style dialog box that replaces the default dialog box.
OFN_EXPLORERIndicates that any customizations made to the Open or Save As
dialog box use the new Explorer-style customization methods. For more
information, see Explorer-Style Hook
Procedures and Explorer-Style Custom
Templates.
By default, the Open and Save As dialog boxes use the
Explorer-style user interface regardless of whether this flag is set. This flag
is necessary only if you provide a hook procedure or custom template, or set the
OFN_ALLOWMULTISELECT flag.
If you want the old-style user interface, omit the OFN_EXPLORER flag and
provide a replacement old-style template or hook procedure. If you want the old
style but do not need a custom template or hook procedure, simply provide a hook
procedure that always returns FALSE.OFN_EXTENSIONDIFFERENTSpecifies that the user typed a file name extension that differs from the
extension specified by lpstrDefExt. The function does not use this flag if
lpstrDefExt is NULL.
OFN_FILEMUSTEXISTSpecifies that the user can type only names of existing files in the File
Name entry field. If this flag is specified and the user enters an invalid
name, the dialog box procedure displays a warning in a message box. If this flag
is specified, the OFN_PATHMUSTEXIST flag is also used. This flag can be used in
an Open dialog box. It cannot be used with a Save As dialog box.
OFN_FORCESHOWHIDDENWindows 2000/XP: Forces the showing of system and hidden files, thus
overriding the user setting to show or not show hidden files. However, a file
that is marked both system and hidden is not shown.
OFN_HIDEREADONLYHides the Read Only check box.
OFN_LONGNAMESFor old-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 with spaces. Explorer-style dialog boxes ignore this flag and always
display long file names.
OFN_NOCHANGEDIRRestores the current directory to its original value if the user changed the
directory while searching for files.
Windows NT 4.0/2000/XP: This flag is ineffective for GetOpenFileName.
OFN_NODEREFERENCELINKSDirects the dialog 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 file name of the file referenced by the shortcut.
OFN_NOLONGNAMESFor old-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
display long file names.
OFN_NONETWORKBUTTONHides and disables the Network button.
OFN_NOREADONLYRETURNSpecifies that the returned file does not have the Read Only check
box selected and is not in a write-protected directory.
OFN_NOTESTFILECREATESpecifies that the file is not created before the dialog box is closed. This
flag should be specified if the application saves the file on a create-nonmodify
network share. When an application specifies this flag, the library does not
check for write protection, a full disk, an open drive door, or network
protection. Applications using this flag must perform file operations carefully,
because a file cannot be reopened once it is closed.
OFN_NOVALIDATESpecifies that the common dialog boxes allow invalid characters in the
returned file name. Typically, the calling application uses a hook procedure
that checks the file name by using the FILEOKSTRING
message. If the text box in the edit control is empty or contains nothing but
spaces, the lists of files and directories are updated. If the text box in the
edit control contains anything else, nFileOffset and nFileExtension are set to values generated by parsing the
text. No default extension is added to the text, nor is text copied to the
buffer specified by lpstrFileTitle. If the value specified by nFileOffset is less than zero, the
file name is invalid. Otherwise, the file name is valid, and nFileExtension and nFileOffset can be used as if the
OFN_NOVALIDATE flag had not been specified.
OFN_OVERWRITEPROMPTCauses the Save As dialog box to generate a message box if the
selected file already exists. The user must confirm whether to overwrite the
file.
OFN_PATHMUSTEXISTSpecifies that the user can type only valid paths and file names. If this
flag is used and 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_READONLYCauses the Read 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 is closed.
OFN_SHAREAWARESpecifies that if a call to the OpenFile function
fails because of a network sharing violation, the error is ignored and the
dialog box returns the selected file name. If this flag is not set, the dialog
box notifies your hook procedure when a network sharing violation occurs for the
file name specified by the user. If you set the OFN_EXPLORER flag, the dialog
box sends the CDN_SHAREVIOLATION
message to the hook procedure. If you do not set OFN_EXPLORER, the dialog box
sends the SHAREVISTRING
registered message to the hook procedure.
OFN_SHOWHELPCauses the dialog box to display the Help button. The hwndOwner member must specify the
window to receive the HELPMSGSTRING
registered messages that the dialog box sends when the user clicks the
Help button. An Explorer-style dialog box sends a CDN_HELP
notification message to your hook procedure when the user clicks the Help
button.
OFN_USESHELLITEMDo not use.
展开全部
你写错了,是OFN_FILEMUSTEXIST,而不是OFN_FILEMUSTEXTST。你把I写成T了,改成OFN_FILEMUSTEXIST之后再编译应该就没问题了。
追问
那怎样做到右键picture控件就能保存上面画的图呢?(我是用CDC类画的)
追答
保存自己画的图片为文件一般要创建兼容DC,兼容位图等,自己写成位图文件比较麻烦,可以使用CImage类来保存成你需要的格式(bmp,jpg等),可以参考下面这个文章:
http://blog.sina.com.cn/s/blog_4db1685d0100tljz.html
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
SLorenzFileDlg dlg(true,".txt",NULL,OFN_FILEMUSTEXTST|OFN_HIDEREADONLY,sz,this);
CFileDialog为基类 ,第一个参数为true代表构造“打开”对话框,第一个参数为false代表构造“另存为”对话框。
CFileDialog为基类 ,第一个参数为true代表构造“打开”对话框,第一个参数为false代表构造“另存为”对话框。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
有几个地方写错啦
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询