First, add the following code in an MFC dialog box to open the file:
Static TCHAR BASED_CODE szFilter [] = _ T ("image (*. bmp ,*. jpg ,*. png) | *. bmp ;*. jpg ;*. png | All Files (*. *) | *. * | "); CFileDialog dlg (TRUE," bmp ", 0, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, szFilter, this); dlg. doModal ();
Microsoft prototype the CFileDialog constructor:
Explicit CFileDialog (BOOL bOpenFileDialog, LPCTSTR success = NULL, LPCTSTR lpszFileName = NULL, DWORD dwFlags = Success | fail, LPCTSTR lpszFilter = NULL, CWnd * success = NULL, DWORD dwSize = 0, BOOL bVistaStyle = TRUE );
Parameter: LPCTSTR lpszFilter = NULL, that is, filter string about file type display
As shown above, for the szFilter writing rules, it determines that in the dialog box that is opened, select (image (*. bmp ,*. jpg ,*. png), the file type is displayed in the dialog box. The rule is found after multiple debugging.
1. In szFilter, for example, image (*. bmp, *. jpg, *. png) appears before "|". The content contained in brackets is the prompt content.
2. After the content is prompted and "|", for the file type displayed in the file dialog box ,*. bmp ;*. jpg ;*. in png, each file type is separated by a semicolon (;).