怎样用C++实现文件另存为功能
包括自定义存储路径和存储名字格式等
包括自定义存储路径和存储名字格式等
答案:C++的WinSDK\MFC可以实现:
MFC方法(要在工程属性里设置MFC支持,最好只在MFC工程里使用):
#include "afxdlgs.h"
CFileDialog fileDlg( 0 /*改为1则为打开对话框*/, 0, 0, 0, "自设文件类型(*.abc)|*.abc|所有文件(*.*)|*.*||", 0);
if (fileDlg.DoModal()==1)
{
AfxMessageBox(fileDlg.GetPathName());
}
WinSDK方法:
#include "windows.h"
char lpFilePath[255]={'\0'};
OPENFILENAME ofn ;
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof (OPENFILENAME) ;
ofn.hwndOwner = hwnd ;
ofn.hInstance = NULL ;
ofn.lpstrFilter = "自设文件类型(*.abc)\0*.abc\0所有文件(*.*)\0*.*\0\0", ;
ofn.lpstrCustomFilter = NULL ;
ofn.nMaxCustFilter = 0 ;
ofn.nFilterIndex = 0 ;
ofn.lpstrFile = lpFilePath ; // 设置存放文件路径缓冲区
ofn.nMaxFile = MAX_PATH ; //缓冲区大小;
ofn.lpstrFileTitle = NULL ; // 设置存放文件名称缓冲区
ofn.nMaxFileTitle = MAX_PATH ; //缓冲区大小;
ofn.lpstrInitialDir = NULL ;
ofn.lpstrTitle = "另寸为" ;
ofn.Flags = 0;
ofn.nFileOffset = 0 ;
ofn.nFileExtension = 0 ;
ofn.lpstrDefExt = 0 ;//ofn.lCustData = 0L ;
ofn.lpfnHook = NULL ;
ofn.lpTemplateName = NULL ;GetOpenFileName (&ofn) ;
上一个:C++中下面这段代码什么意思
下一个:C++用队列实现火车车厢重排问题