A static control to display DIBs | CodeGuru

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. […]

Written By
CodeGuru Staff
CodeGuru Staff
Jan 25, 2000
1 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 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

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.