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



Comments

  • Just for clarity.

    Posted by Legacy on 02/25/2000 12:00am

    Originally posted by: Chad Wanless

    At first I was a litle confused by the mention of a stc32 static control. I couldn't find it in the dialog resource I downloaded. For those of you who may be having troubles placing the preview static control to the right side (not the bottom), the solution is this. Jorge had drawn a text static control on left side of the dialog form very thin (8 +- pixels wide), duplicate this control in your projects as he has and you will have no problems.

    Chad Wanless

    Reply
  • Another small bug!

    Posted by Legacy on 05/06/1999 12:00am

    Originally posted by: Andrew Truckle

    I noticed that if you look closely at the "cross" which is drawn when there is no bitmap to display, the top right endpoint is past the white bitmap area. Likewise the bottom left startpoint begins one pixel in.

    This became visible when I selected a file which had a preview and I could see a small dot in the top right corner.

    It is resolved if you modify lines 137/138 in file DibStatic.cpp to look like this:

    dc.MoveTo(PaintRect.right - 1, PaintRect.top);
    dc.LineTo(PaintRect.left - 1, PaintRect.bottom);

    This should fix the problem in the short term. But it might need looking into further.

    Reply
  • A Small Bug

    Posted by Legacy on 03/24/1999 12:00am

    Originally posted by: Rick York

    I found a small bug in CDIBStatic::PaintDib.
    
    The effect of the bug can be seen when drawing certain
    bitmaps that are not square. They will appear outside
    the rectangle or not centered.

    Lines 108 and 109 of DIBStatic.cpp read :

    nDestWidth = m_DIB.Height();
    nDestHeight = m_DIB.Width();

    They should be reversed to read :

    nDestWidth = m_DIB.Width();
    nDestHeight = m_DIB.Height();

    Reply
  • Can I get project file about it

    Posted by Legacy on 01/22/1999 12:00am

    Originally posted by: Eric Lee

    If I get a project file about bitmap preview on Dialog, it's my goodness.
    Please would anybody send me project file about bitmap preview on Dialog?

    Reply
  • How to use?

    Posted by Legacy on 01/12/1999 12:00am

    Originally posted by: Torbj�rn Josefsson

    I've tried using this to the best of my (meager) ability..
    Do you have any tips?

    Regards
    /Torbj�rn Josefsson

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • As all sorts of data becomes available for storage, analysis and retrieval - so called 'Big Data' - there are potentially huge benefits, but equally huge challenges...
  • The agile organization needs knowledge to act on, quickly and effectively. Though many organizations are clamouring for "Big Data", not nearly as many know what to do with it...
  • Cloud-based integration solutions can be confusing. Adding to the confusion are the multiple ways IT departments can deliver such integration...

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date