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 is derived from CFileDialog MFC class. It basically overrides CFileDialog::DoModal and constructs the file types filter.
// Get a list of available decoders or encoders
// for File Open or File Save As dialog, respectively
WICComponentType type = m_bOpenFileDialog ? WICDecoder : WICEncoder;
// Constructs MFC-style filter (using '|' as separator.
// translate MFC-style filter into WinAPI-style filter (using '\0' as separator).
// clear the codecs info list
// call base class method
For implementation details, download the demo project attached here.
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.
- Codexpert blog: How to enumerate WIC codecs?
- Codeguru article: File Open and Save As Dialogs for MFC Applications Using GDI+