A previous article showed how to enumerate WIC (Windows Imaging Component) codecs, that are available in system.
Now, let’s use the codecs list in order to make File Open and File Save As dialogs which are dealing with WIC-compliant image files, i.e. having “File of type” filter list according to available WIC codecs (see the images, below).


CWICFileDialog class
CWICFileDialog is derived from CFileDialog MFC class. It basically overrides CFileDialog::DoModal and constructs the file types filter.
INT_PTR CWICFileDialog::DoModal() { // Get a list of available decoders or encoders // for File Open or File Save As dialog, respectively WICComponentType type = m_bOpenFileDialog ? WICDecoder : WICEncoder; CodecsInfoList list; VERIFY(SUCCEEDED(_FillCodecsInfoList(type, list))); // Constructs MFC-style filter (using '|' as separator. _ConstructMFCStyleFilter(list); // translate MFC-style filter into WinAPI-style filter (using '\0' as separator). _TranslateFilter(); // clear the codecs info list _ClearCodecsInfoList(list); // call base class method return CFileDialog::DoModal(); }
For implementation details, download the demo project attached here.
Demo project
The demo project is just a simple dialog-based MFC application that uses CWICFileDialog. It does nothing else but only shows the file dialogs.
Of course, in practice, you can use CWICFileDialog class in more complex applications like image file viewers, image file converters, and so on.
Resources
- MSDN Library: CFileDialog Class
- Windows Dev Center: Windows Imaging Component
See also
- Codexpert blog: How to enumerate WIC codecs?
- Codeguru article: File Open and Save As Dialogs for MFC Applications Using GDI+