A static control to display DIBs

This article describes a class (CDibStatic) that implements a static control used to display dibs. The control has a CDib member, which displays itself with the parameters passed by the CDibStatic class. The CDib class encapsulates the functionality provided in dibapi.h (DIBLOOK sample) and is described in an article in the images & palettes section.

The main features of the CDibStatic class are:

  • The dib can be loaded directly from disk
  • Includes palette support
  • The image is centered/stretched automatically in the control client area

The palette support is implemented using handlers for the WM_QUERYNEWPALETTE and WM_PALETTECHANGED windows messages, so you have to ensure in your program that the control receives these messages. If the palette never changes the CDib class paints the image with the right palette selected the first time. If the control is used in modal dialogs (fileopen for instance), the palette changes can be due only to other applications, thus realizing palette when gaining focus will always maintain the right colors. You can realize the palette any time you want using the DoRealizePalette member function.

This class has been used (among other things) to implement a standard file open dialog with preview (and without any custom hooks) and a completely object oriented DIBLOOK. These articles can be found on the dialogs section and the samples section respectively.

Downloads

Download demo project - 40 Kb
Download source - 8 Kb


Comments

  • Bug, width and height are exchanged

    Posted by Legacy on 08/15/2000 12:00am

    Originally posted by: Albert L Faber

    I noticed a small bug in the CDibStatic class, the problem occursonly when the DIB size is smaller than the Client paint area:

    When I replaced the following two lines (in CDIBStatic::PaintDib method) it
    seems to work correct

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

    with:

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


    Apprently the Width and the Height are mixed up

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

Top White Papers and Webcasts

  • Intelligent N+X Redundancy, Placement Affinities, & Future Proofing in the Virtualized Data Center Virtualization brought about the ability to simplify business continuity management in IT. Workload portability and data replication capabilities mean that physical infrastructure failures no longer need impact application services, and they can rapidly be recovered even in the event of complete site failure. However, Enterprises and Service Providers face new challenges ensuring they have enough compute …

  • Live Event Date: August 14, 2014 @ 2:00 p.m. ET / 11:00 a.m. PT Data protection has long been considered "overhead" by many organizations in the past, many chalking it up to an insurance policy or an extended warranty you may never use. The realities of today make data protection a must-have, as we live in a data driven society. The digital assets we create, share, and collaborate with others on must be managed and protected for many purposes. Check out this upcoming eSeminar and join eVault Chief Technology …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds