void CFilterDlg::OnButton1()
{
OPENFILENAME ofn;
char* filter = "doc\0*.doc\0xls\0*.xls\0ppt\0*.ppt\0all\0*.*\0\0";
ZeroMemory(&ofn,sizeof(ofn));
ofn.lStructSize=sizeof(ofn);
ofn.hwndOwner=this->GetSafeHwnd();
ofn.lpstrFilter=filter; //文件过滤器
ofn.lpstrCustomFilter=NULL;
ofn.nFilterIndex=0;
char filename[128];
filename[0]='\0';
ofn.lpstrFile=filename; //文件名
ofn.nMaxFile=128;
ofn.lpstrFileTitle=NULL;
ofn.lpstrInitialDir=NULL; //初始路径
ofn.lpstrTitle="打开文件\0"; //标题
ofn.Flags=OFN_FILEMUSTEXIST|OFN_HIDEREADONLY|OFN_LONGNAMES|OFN_PATHMUSTEXIST;
ofn.lpstrDefExt=NULL; //默认扩展名
if(GetOpenFileName(&ofn)==IDOK)
{
MessageBox(filename,"选中的文件是",MB_OK);
}
}