我想在视图区显示BMP图像,因此想修改系统“打开文件”对话框中的文件默认格式为*.bmp,我在***App文件中添加了对应“打开文件”菜单ID号的函数,但不知道为什么运行时不起作用,感觉好像这个函数没有执行,请大家帮忙看看。多谢~~void CSeparated_CannyApp::OnFileOpen()
{
    // TODO: Add your command handler code here
    CString strOpenFileType = "bitmap files (*.bmp;*.dib)|*.bmp; *.dib|All Files (*.*)|*.*||";
    CFileDialog FileDlg(TRUE, "*.bmp", NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, strOpenFileType);    if (FileDlg.DoModal() == IDOK)
      OpenDocumentFile(FileDlg.m_ofn.lpstrFile);
}

解决方案 »

  1.   

    CFileDialog m_SoundDlg(TRUE,NULL,NULL,NULL,"ALL Files(*.wav)|*.wav||",NULL);
    CString str("",10000);
    m_SoundDlg.m_ofn.lpstrFile=str.GetBuffer(10000);
    POSITION pos=m_SoundDlg.GetStartPosition();
    CString strPathName("",256);
    CFileStatus status;
    while(pos!=NULL)
    {
    strPathName=m_SoundDlg.GetNextPathName(pos);
    CFile::GetStatus(strPathName,status);
    }
    if(m_SoundDlg.DoModal()==IDOK)
    {
    strPathName = m_SoundDlg.GetPathName();
    this->m_sound_file = strPathName;
    UpdateData(FALSE);
    }
      

  2.   


    BOOL GetFileName(LPSTR szName)
    {
    ZeroMemory(szName,MAX_PATH);
    OPENFILENAME ofn;
    ofn.lStructSize       = sizeof(OPENFILENAME);
    ofn.hwndOwner         = AfxGetMainWnd()->m_hWnd;
    ofn.lpstrFilter       = NULL;
    ofn.lpstrFilter       = "Video (*.bmp)\0*.bmp\0All Files (*.*)\0*.*\0";
    ofn.lpstrCustomFilter = NULL;
    ofn.nFilterIndex      = 1;
    ofn.lpstrFile         = szName;
    ofn.nMaxFile          = MAX_PATH;
    ofn.lpstrInitialDir   = NULL;
    ofn.lpstrTitle        = NULL;
    ofn.lpstrFileTitle    = NULL;
    ofn.lpstrDefExt       = NULL;
    ofn.Flags             = OFN_FILEMUSTEXIST | OFN_READONLY | OFN_PATHMUSTEXIST;
    return ::GetOpenFileName((LPOPENFILENAME)&ofn);}
    这样调用:
    void CEX001Doc::OnFileOpen() 
    {
    // TODO: Add your command handler code here
           TCHAR szName[MAX_PATH];
    GetFileName(szName);
    AfxMessageBox(szName);
    }