MFC-extension WIC File Dialogs

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).

WIC Open File Dialog
WIC Open File Dialog


WIC Save As File Dialog
WIC Save As File Dialog

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.

   // translate MFC-style filter into WinAPI-style filter (using '\0' as separator). 

   // clear the codecs info 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.


See also


Leave a Comment