window下打开文件选择对话框和浏览对话框的方式

1.文件对话框的打开代码

CFileDialog dlg(TRUE , ".map" , NULL , OFN_HIDEREADONLY , "map文件(*.map)|*.map|所有文件(*.*) |*.*||" );
CString file_path;
CString temp_path;

if (dlg.DoModal() == IDOK) {
file_path = dlg.GetPathName();//获取文件的全路径
//file_path.Replace("\\","\\\\");//将/替换为//
file_path.Replace("\\","/");
temp_path.Format("%s%s",file_path.GetBuffer(1),"/");
}

<wbr> CFileDialog文件选择对话框的使用:<br style="line-height:22px"><wbr><wbr><wbr> 首先构造一个对象并提供相应的参数,构造函数原型如下:<br style="line-height:22px"><wbr><wbr><wbr> CFileDialog::CFileDialog(<br style="line-height:22px"><wbr><wbr><wbr><wbr><wbr><wbr><wbr> BOOL bOpenFileDialog, //为TRUE则显示打开对话框,为FALSE则显示保存对话文件对话框<br style="line-height:22px"><wbr><wbr><wbr><wbr><wbr><wbr><wbr> LPCTSTR lpszDefExt = NULL, //默认的文件扩展名<br style="line-height:22px"><wbr><wbr><wbr><wbr><wbr><wbr><wbr> LPCTSTR lpszFileName = NULL, //默认的文件名<br style="line-height:22px"><wbr><wbr><wbr><wbr><wbr><wbr><wbr> DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, //设定风格<br style="line-height:22px"><wbr><wbr><wbr><wbr><wbr><wbr><wbr> LPCTSTR lpszFilter = NULL, //列出可供选择的文件类型和相应的扩展名<br style="line-height:22px"><wbr><wbr><wbr><wbr><wbr><wbr><wbr> CWnd* pParentWnd = NULL //父窗口句柄指针<br style="line-height:22px"><wbr><wbr><wbr> );<br style="line-height:22px"><br style="line-height:22px"> LPCTSTR lpszFilter 参数格式如:"Chart Files (*.xlc)|*.xlc|Worksheet Files (*.xls)|*.xls|Da<wbr style="line-height:22px">ta Files (*.xlc;*.xls)|*.xlc;*.xls|All Files (*.*)|*.*||";文件类型说明和扩展名间用 | 分隔,同种类型文件的扩展名间可以用 ; 分割,每种文件类型间用 | 分隔,末尾用 || 指明。</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>

2.文件夹浏览对话框的代码

TCHAR path[1024];
BROWSEINFO info={0};

info.hwndOwner = NULL;
info.pidlRoot = NULL;
info.lpszTitle = "选择合并后文件目录";
info.ulFlags = 0;
info.pszDisplayName = path;
info.lpfn = NULL;
info.lParam = NULL;
info.iImage = NULL;

LPCITEMIDLIST pidl=SHBrowseForFolder(&info);

if( pidl == NULL) return;

SHGetPathFromIDList(pidl,path);

m_DestBrowseDir.Format("%s%s",path,"\\");
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值