方法一:
CString str;
str="BMP FILE(*.bmp)|*.bmp|JPG FILE(*.jpg)|*.jpg||";
CFileDialog dlg(TRUE, NULL, NULL, NULL, str);
dlg.DoModal();
方法二:
static char BASED_CODE szFilter[]="BMP FILE(*.bmp)\0*.bmp\0JPG FILE(*.jpg)\0*.jpg\0\0";
CFileDialog dlg(TRUE);
dlg.m_ofn.lpstrFilter = szFilter;
dlg.DoModal();
Note, however, that if you plan to use this string to directly update the OPENFILENAME structure, that you should delimit your strings with the null character, '\0', instead of the vertical bars (|).