vc里资源菜单项里添加了一个菜单,文件-打开,这里面函数怎么实现浏览自己电脑文件,自由选取一个文件
vc里资源菜单项里添加了一个菜单,文件-打开,这里面函数怎么实现浏览自己电脑文件,自由选取一个文件呢。像记事本的文件-打开按钮...
vc里资源菜单项里添加了一个菜单,文件-打开,这里面函数怎么实现浏览自己电脑文件,自由选取一个文件呢。像记事本的文件-打开按钮
展开
1个回答
展开全部
加上头文件#include <commdlg.h>
其格式如下
OPENFILENAME ofn;
char path[MAX_PATH];
static TCHAR szFilter[] = TEXT ("Text Files (*.TXT)\0*.txt\0") \
TEXT ("ASCII Files (*.ASC)\0*.asc\0") \
TEXT ("All Files (*.*)\0*.*\0\0") ;
//这里是定义要查找的文件后缀名
ofn.lStructSize = sizeof (OPENFILENAME) ;
ofn.hwndOwner = hwnd ;
ofn.hInstance = NULL ;
ofn.lpstrFilter = szFilter ;
ofn.lpstrCustomFilter = NULL ;
ofn.nMaxCustFilter = 0 ;
ofn.nFilterIndex = 0 ;
ofn.nMaxFile = MAX_PATH ;
ofn.nMaxFileTitle = MAX_PATH ;
ofn.lpstrInitialDir = NULL ;
ofn.lpstrTitle = NULL ;
ofn.Flags = 0 ; // Set in Open and Close functions
ofn.nFileOffset = 0 ;
ofn.nFileExtension = 0 ;
ofn.lpstrDefExt = TEXT ("txt") ;
ofn.lCustData = 0L ;
ofn.lpfnHook = NULL ;
ofn.lpTemplateName = NULL ;
ofn.hwndOwner = hwnd ;
ofn.lpstrFile = path ;
ofn.lpstrFileTitle = NULL ;
ofn.Flags = OFN_HIDEREADONLY | OFN_CREATEPROMPT ;
GetOpenFileName (&ofn) ;//打开文件对话框
GetSaveFileName(&ofn);//保存文件对话框
其格式如下
OPENFILENAME ofn;
char path[MAX_PATH];
static TCHAR szFilter[] = TEXT ("Text Files (*.TXT)\0*.txt\0") \
TEXT ("ASCII Files (*.ASC)\0*.asc\0") \
TEXT ("All Files (*.*)\0*.*\0\0") ;
//这里是定义要查找的文件后缀名
ofn.lStructSize = sizeof (OPENFILENAME) ;
ofn.hwndOwner = hwnd ;
ofn.hInstance = NULL ;
ofn.lpstrFilter = szFilter ;
ofn.lpstrCustomFilter = NULL ;
ofn.nMaxCustFilter = 0 ;
ofn.nFilterIndex = 0 ;
ofn.nMaxFile = MAX_PATH ;
ofn.nMaxFileTitle = MAX_PATH ;
ofn.lpstrInitialDir = NULL ;
ofn.lpstrTitle = NULL ;
ofn.Flags = 0 ; // Set in Open and Close functions
ofn.nFileOffset = 0 ;
ofn.nFileExtension = 0 ;
ofn.lpstrDefExt = TEXT ("txt") ;
ofn.lCustData = 0L ;
ofn.lpfnHook = NULL ;
ofn.lpTemplateName = NULL ;
ofn.hwndOwner = hwnd ;
ofn.lpstrFile = path ;
ofn.lpstrFileTitle = NULL ;
ofn.Flags = OFN_HIDEREADONLY | OFN_CREATEPROMPT ;
GetOpenFileName (&ofn) ;//打开文件对话框
GetSaveFileName(&ofn);//保存文件对话框
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询