文件打开(保存)对话框:GetOpenFileName和 GetSaveFileName
来源:互联网 发布:网络信息安全事件 编辑:程序博客网 时间:2024/05/17 08:18
void Test() {TCHAR strFilter[]= _T("Bitmap Files(*.bmp)\0*.bmp\0")_T("JPEG Files(*.jpeg;*jpg)\0*.jpeg;*.jpg\0")_T("PNG Files(*.png)\0*.png\0")_T("All Files(*.*)\0*.*\0");TCHAR strFile[MAX_PATH]= _T("未命名");TCHAR strFileTitle[256]= {0};TCHAR strInitiaDir[]= _T("D:\\DeskTop");TCHAR strTitle[]= _T("请选择");OPENFILENAME ofn; ZeroMemory(&ofn, sizeof(ofn));// 指定结构的大小,以字节为单位ofn.lStructSize= sizeof(ofn);/*Handle to the window that owns the dialog box. This member can be any valid window handle, or it can be NULL if the dialog box has no owner.*/ofn.hwndOwner = m_hWnd;// Not supported.//ofn.hInstance;// 过滤器字符串的长指针,需以两个空字符结尾ofn.lpstrFilter = strFilter;// Not supported.//ofn.lpstrCustomFilter;// Not supported.//ofn.nMaxCustFilter;// 过滤器序号(由1开始,如果该值为0表示第一个)ofn.nFilterIndex= 3;/*指向包含初始化文件名编辑控件使用的文件名的缓冲。如果不需要初始值,这个缓冲的第一个字符必须是NULL。当GetOpenFileName或GetSaveFileName函数返回成功时,这个缓冲包含驱动器,路径,文件名,及所选择的文件的扩展名。 If the buffer is too small, the function returns FALSE. In this case, the first two bytes of the lpstrFile buffer contain the required size, in bytes or characters.*/ofn.lpstrFile= strFile;/*Specifies the size, in bytes (ANSI version) or 16-bit characters (Unicode version), of the buffer pointed to by lpstrFile. The GetOpenFileName and GetSaveFileName functions return FALSE if the buffer is too small to contain the file information. The buffer should be at least 256 characters long.*/ofn.nMaxFile= sizeof(strFile);// 指向接收选择的文件的文件名和扩展名的缓冲(不带路径信息)。这个成员可以是NULL。ofn.lpstrFileTitle= strFileTitle;/*指定lpstrFileTitle缓冲的大小,以TCHARs为单位。对于ANSI版本,是字节的个数;对于Unicode版本,是字节的个数。如果lpstrFileTitle是NULL,这个成员被忽略。*/ofn.nMaxFileTitle= sizeof(strFileTitle);// 打开对话框的初始目录,可以为NULLofn.lpstrInitialDir= strInitiaDir;// 打开对话框标题栏的提示文字ofn.lpstrTitle= strTitle;/*A bitmask of flags used 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.Flags= 0;// 指定从路径开始到通过lpstrFile指定的文件名字符串基于0的偏移ofn.nFileOffset= 0;// 指定从路径开始到通过lpstrFile指定的文件名字符串中扩展名基于0的偏移ofn.nFileExtension= 0;/*指向包含默认扩展名的缓冲。如果用户忘记输入扩展名,GetOpenFileName和GetSaveFileName附加这个扩展名到文件名中。这个字符串可以是任一长度,但但只有头三个字符被附加。字符串不应该包含一个句点(.)。如果这个成员是NULL并且用户忘记了输入一个扩展名,那么将没有扩展名被附加。*/ofn.lpstrDefExt= _T("bmp");//ofn.lCustData;// Not supported.//ofn.lpfnHook;// Not supported.//ofn.lpTemplateName;// Not supported.CString str;if (GetOpenFileName(&ofn)){str = ofn.lpstrFile;AfxMessageBox(str);}if (GetSaveFileName(&ofn)){str = ofn.lpstrFile;AfxMessageBox(str);}}
0 0
- 文件打开(保存)对话框:GetOpenFileName和 GetSaveFileName
- 使用 OPENFILENAME 以及 GetOpenFileName、GetSaveFileName 实现打开,保存对话框
- 通用对话框GetOpenFileName&&GetSaveFileName
- MFC 对话框打开文件失败(GetOpenFileName())
- 资源地址;浏览和打开文件;GetOpenFileName;GetSaveFileName;OPENFILENAME;PtrToStringChars;.NET类库的打开文件夹操作
- WIN32的保存文件对话框GetSaveFileName
- GetOpenFileName/GetSaveFileName之Crash和pdfshell.dll
- 打开文件对话框和保存文件对话框
- 打开和保存文件对话框
- 文件打开和保存对话框
- 打开对话框和保存对话框(文件操作)
- 使用文件对话框打开和保存文件
- <MFC>打开文件和保存文件对话框
- WinAPI:GetOpenFileName、GetSaveFileName、OFNHookProc
- (8)QFileDialog---文件打开和保存对话框
- 打开和保存文件的对话框
- C# 打开和保存文件对话框
- MFC 文件打开和保存对话框
- JSP九大内置对象
- Forming Quiz Teams+uva+状态压缩
- 每日一道算法题:Jump Game
- 第11 周 项目7-太乐了(1)
- Linux中断梳理
- 文件打开(保存)对话框:GetOpenFileName和 GetSaveFileName
- mysql复制原理及作用分析(2014-11-11)
- 第11周项目2-2:求四个数的最大公约数
- 【iOS开发-72】设置状态栏的两种方式、程序生命周期以及更好地理解几大类(对象)之间的关系
- Oracle数据库中重复数据删除方法:部分去重+完全去重
- Flex多样化饼图样式(颜色渐变,点击分离,环形)
- POJ 2653 Pick-up sticks 判断线段相交
- DllMain()限入死锁问题分析 (一)
- Map可以使用的坐标系