在文件对话框中仅选择bin文件 [英] Select only bin Files in File Dialogue

查看:83
本文介绍了在文件对话框中仅选择bin文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设计了一个应用程序,其中Browse按钮事件应该选择.bin文件,但是我写了那个事件选择所有文件;我复制下面的代码,请给出我的问题解决方案。

I design one application in which Browse button event should select the .bin files,but I write that event select all files;I copy my code below,please give my problem solution.

CFileDialog CFiledlg(TRUE,_T(".bin"));
    if(CFiledlg.DoModal()==IDOK)
    {
        m_Input_File_Path=CFiledlg.GetPathName();
        char *file_path=new char[m_Input_File_Path.GetLength()+1];
        wcstombs(file_path,m_Input_File_Path,m_Input_File_Path.GetLength()+1);
        UpdateData(FALSE);
delete[] file_path
    }

推荐答案

// szFilters is a text string that includes two file name filters:
// "*.bin" for "Binary Files" and "*.*' for "All Files."
char CChildFrame::szFilters[]=
   "Binary Files (*.bin)|*.bin";

// Create an Open dialog; the default file name extension is ".bin".
CFileDialog CFiledlg (TRUE, "bin", "*.bin",
   OFN_FILEMUSTEXIST| OFN_HIDEREADONLY, szFilters, this);

// Display the file dialog. When user clicks OK, fileDlg.DoModal()
// returns IDOK
if( fileDlg.DoModal ()==IDOK )
{
     m_Input_File_Path=CFiledlg.GetPathName();
     char *file_path=new char[m_Input_File_Path.GetLength()+1];
     wcstombs(file_path,m_Input_File_Path,m_Input_File_Path.GetLength()+1);
     UpdateData(FALSE);
     delete[] file_path
}


这篇关于在文件对话框中仅选择bin文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆