Standard File Open dialog with preview | CodeGuru

Standard File Open dialog with preview

This article describes a completely object oriented standard file open dialog with preview. No custom hook function, just common MFC message maps. The dialog has a CDibStatic member, which displays the preview image when available. The CDibStatic class encapsulates a static control that displays images and is described in an article in the static controls […]

Written By
CodeGuru Staff
CodeGuru Staff
Apr 3, 1999
2 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

This article describes a completely object oriented standard file open dialog with preview.
No custom hook function, just common MFC message maps. The dialog has a CDibStatic member,
which displays the preview image when available. The CDibStatic class encapsulates a static
control that displays images and is described in an article in the static controls section.

This is how the dialog looks like:


The template for the dialog is a normal developer studio dialog template. Note however,
the use of the stc32 static control. As it hasn’t any text in it, it is invisible unless
you select it. This static control will serve as a place holder for the standard file
dialog controls, thus establishing the position of the newly added controls in respect to
the standards. If there is no stc32 control specified in the template, all the new controls
will be placed below the standard controls. Otherwise, the common file dialog will look at
the size of the stc32 control to attempt to fit all the standard controls in it. If it is
not big enough, it is resized to make room for the standard controls, and then the new controls
are repositioned with respect to the resized stc32 control.

Palette support is included within the dialog class. It is implemented using handlers for
the WM_QUERYNEWPALETTE and WM_PALETTECHANGED windows messages, so you have to ensure in your
program that the dialog receives these messages. If the palette never changes, the image is
painted with the right palette selected the first time. Since the standard dialogs are modal,
the palette changes can be due only to other applications (unless you change it in another
thread), thus realizing palette when gaining focus should always maintain the right colors.
You can realize the palette at any time you wish by sending a WM_QUERYNEWPALETTE message to
the CDibStatic control, for instance.

This class has been used (among other things) to implement a completely object oriented DIBLOOK.
This article can be found in the samples section.


Download Source Code

Date Last Updated: April 3, 1999

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.