Irregular Shaped Bitmap Dialog | CodeGuru

Irregular Shaped Bitmap Dialog

The CBitmapDialog class allows you to create a dialog that has a bitmap background, and to have a specified color in the background be transparent. This allows the dialog to be in other shapes than a box, like the one shown above. Usage Use this class like CDialog, but there are several extra functions that […]

Written By
CodeGuru Staff
CodeGuru Staff
Jan 29, 2001
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

The CBitmapDialog class allows you to create a dialog that has a bitmap background, and to have a specified color in the background be transparent. This allows the dialog to be in other shapes than a box, like the one shown above.

Usage

Use this class like CDialog, but there are several extra functions that you can use:

// ** Constructors **
// Use the normal CDialog constructors plus the following 
// as the last four parameters:
// 
// LPCTSTR	lpszResourceName
// UINT		nIDResource
// LPCTSTR	lpszFilename
// CBitmap	*pBitmap
// 
// Example:
// CDialog(int,CWnd*)):CBitmapDialog(IDD_MAINDIALOG, 
                                     this,
                                     NULL,
                                     IDB_BITMAP,
                                     NULL,
                                     NULL);
//
// Use at most one of these parameters and leave the rest 
// NULL or 0. If you do not want to set a bitmap in the 
// constructor, look below.
// ** Bitmap Setting **
// Loads a bitmap from a resource string or filename.
//  Leave either lpszResourceName or lpszFilename NULL.
BOOL LoadBitmap (LPCTSTR lpszResourceName,
                 LPCTSTR lpszFilename);
// Loads a bitmap from a resource ID
BOOL LoadBitmap (int nIDResource);
// Makes a copy of a given bitmap and uses the copy.  
// This is like SetBitmap but you are not responsible 
// for handling the bitmap.
BOOL CopyBitmapFrom (CBitmap *pBitmap);
// Uses the bitmap you specify.  NOTE: You are responsible 
// for handling the bitmap.
void SetBitmap (CBitmap *pBitmap);
// ** Transparency **
// Specifies whether the window should use transparency.
//  TRUE for transparent, FALSE for opaque. (default is 
//  FALSE)
void SetTransparent (BOOL bTransparent);
BOOL GetTransparent ();
// Specifies the color that you want to be transparent.
void SetTransColor (COLORREF col);
COLORREF GetTransColor ();
// Specifies whether static (text) controls have a 
// transparent background.
//  TRUE for transparent, FALSE for opaque. (default 
//  is TRUE)
void SetStaticTransparent (BOOL bTransparent);
BOOL GetStaticTransparent ();
// ** Dragging **
// With a transparent dialog, you usually won’t have a 
// caption (like my example). 
//  These functions make it so that you can drag anywhere 
//  on the dialog to move it.  TRUE is on and FALSE is off. 
//  (default is FALSE)
void SetClickAnywhereMove (BOOL bMove);
BOOL GetClickAnywhereMove ();

Tips

* In the resource editor, you can’t tell exactly how big
the dialog will need to be to hold the entire bitmap. You
could either try out different sizes, or if you don’t have
“show window contents while dragging” (windows option) enabled,
you could drag the dialog and see how much extra dialog you
have on the edge when it shows you the frame.

* Dialogs that use transparency usually look best without a
caption or a border. In the resource editor for your dialog,
uncheck “title bar” and set “border” to “none.”

How it works

It overrides CWnd::OnEraseBackground() to draw the bitmap as the background.
It overrides CWnd::OnCtlColor() to make static controls transparent.
It makes parts of the window transparent by combining many small window regions. (look at CBitmapDialog::MakeWindowRgn())
It allows you to drag anywhere to move by making Windows think that you clicked on the caption (even if there is no caption bar).

Advertisement

Downloads

Download demo project (include Release build) – 100 Kb

Download source – 5 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.