怎么使用"打开文件对话框":CFileDialog?内容见内

cieon_123 2005-05-18 11:08:08
我想在选择打开文件时,使用自定义的对话框:
使用如下:
重载
void CMainFrame::OnFileOpen()
{
// TODO: Add your command handler code here
CString filter;
filter = "All Supported Files(*.ini)|*.ini|";
filter+= "All Files(*.*)|*.*||";
CFileDialog dlg(TRUE,NULL,NULL,0,(LPCSTR)filter);
if (dlg.DoModal() != IDOK)
return;
.......

return;
}
直接运行没有问题,但是debug时运行到if(dlg.DoModal()....)时出现
User breakpoint called from code at 0x77f9f9df
然后再也无法继续,这样后面的我就没法dubug了,请问这是怎么回师?
是不是不能重载这个函数?


...全文
169 点赞 收藏 3
写回复
3 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
bobob 2005-05-18
哪个是mfc的问题,使用如下代码

static OPENFILENAME ofn={0};

TCHAR szName[MAX_PATH];
*szName = 0;

// Fill in standard structure fields
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = AfxGetMainWnd()->GetSafeHwnd();
ofn.lpstrFilter = NULL;
ofn.lpstrFilter = "txt files\0*.txt\0All files\0*.*\0";
ofn.lpstrCustomFilter = NULL;
ofn.nFilterIndex = 1;
ofn.lpstrFile = szName;
ofn.nMaxFile = MAX_PATH;
ofn.lpstrTitle = TEXT("Open txt File...\0");
ofn.lpstrFileTitle = NULL;
ofn.lpstrDefExt = TEXT("*\0");
ofn.Flags = OFN_FILEMUSTEXIST | OFN_READONLY | OFN_PATHMUSTEXIST;

// Remember the path of the first selected file

// Create the standard file open dialog and return its result
GetOpenFileName((LPOPENFILENAME)&ofn);
strFileName.Format("%s",ofn.lpstrFile);
回复
dongfa 2005-05-18
我这里没有问题呀.
回复
newzk 2005-05-18
OPENFILENAME OpenFileName;

// Structure for common dialog File/Open
TCHAR szFilter[]=__TEXT("JPEG Images(*.jpg)\0*.jpg\0");
TCHAR szFile[MAX_PATH];

// Initialize variables
szFile[0] = __TEXT('\0');
OpenFileName.lStructSize = sizeof(OPENFILENAME);
OpenFileName.hwndOwner = hWnd;
OpenFileName.hInstance = hInst;
OpenFileName.lpstrFilter = szFilter;
OpenFileName.lpstrCustomFilter = (LPTSTR) NULL;
OpenFileName.nMaxCustFilter = 0L;
OpenFileName.nFilterIndex = 1L;
OpenFileName.lpstrFile = szFile;
OpenFileName.nMaxFile = sizeof(szFile);
OpenFileName.lpstrFileTitle = NULL;
OpenFileName.nMaxFileTitle = 0;
OpenFileName.lpstrInitialDir = NULL;
OpenFileName.lpstrTitle = __TEXT("open jpg file");
OpenFileName.nFileOffset = 0;
OpenFileName.nFileExtension = 0;
OpenFileName.lpstrDefExt = NULL; // No default extension
OpenFileName.lCustData = 0;
OpenFileName.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST |
OFN_HIDEREADONLY | OFN_EXPLORER | OFN_LONGNAMES;

if (GetOpenFileName (&OpenFileName))
{
lstrcpy(szFileName, OpenFileName.lpstrFile);

}
回复
相关推荐
发帖
VC/MFC
创建于2007-09-28

1.5w+

社区成员

VC/MFC相关问题讨论
申请成为版主
帖子事件
创建了帖子
2005-05-18 11:08
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……