Click here to Skip to main content
12,693,891 members (33,417 online)
Click here to Skip to main content
Add your own
alternative version


84 bookmarked

MFC Transparent CDialog Demo

, 3 Dec 2002 CPOL
Rate this:
Please Sign up or sign in to vote.
A transparent dialog
<!-- Download Links --> <!-- Article image -->

Sample Image - transparentdialog.gif


This dialog is derived from CDialog. A bitmap is loaded from a file and a region created based on a transparent colour. The bitmap is then used to paint the dialog. This demo also demonstrates dragging the dialog by clicking anywhere on a visible portion of the dialog, timer events and a button on the transparent dialog.

It is perfect to be used as a splash screen or similar application or as a skeleton application for non rectangular windows that are shaped by a supplied bitmap.

The code

You should be able to use this demo as a skeleton application for your own project.

A standard CDialog MFC EXE application was created with the wizard and apart from the standard supplied code, the following functions were overridden.

void OnClose()Used to clean up some resources on exit.
void OnPaint()Used to paint the bimap into the region.
void OnSize(UINT nType, int cx, int cy)Used to create the region and position and resize the dialog.
void OnLButtonDown(UINT nFlags, CPoint point)To allow the dialog to be dragged by clicking anywhere.

A button was created to allow the user to close the dialog. A timer was created to demonstrate auto closing after a period of time.

The image is a normal bmp file that is loaded by the app and used to paint the dialog. TRANSPARENTCOLOR is defined in the dialog class header as bright purple (RGB(255, 0, 255), but this could be changed to any colour you like.

The dialog window is auto sized to the size of the loaded bitmap then a region created based on the transparent colour. The dialog is then positioned in the centre of the current screen. This was done as an example for those who want to use this application as a splash windows.

An example of using this class is as follows:

CTransparentDialogDlg dlg;
int nResponse = dlg.DoModal();

The button serves no real purpose and was made a close button simply to demonstrate using a button.


V1.0 initial release 27th November 2002


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Nic Wilson
Web Developer
Australia Australia
No Biography provided

You may also be interested in...

Comments and Discussions

GeneraliY undefined. Pin
Joel Brockman9-Feb-11 12:21
memberJoel Brockman9-Feb-11 12:21 
Generalbuttons Pin
basculo29-Apr-09 12:28
memberbasculo29-Apr-09 12:28 
GeneralQuestion on the way you exit application Pin
andyluu19-Jan-09 9:30
memberandyluu19-Jan-09 9:30 
GeneralRe: Question on the way you exit application Pin
Nic Wilson19-Jan-09 11:50
memberNic Wilson19-Jan-09 11:50 
Generalit's great. Pin
Mohamad Kaifi8-May-08 1:19
memberMohamad Kaifi8-May-08 1:19 
GeneralRe: it's great. Pin
Nic Wilson19-Jan-09 11:54
memberNic Wilson19-Jan-09 11:54 
GeneralGood, It's what I'm looking for ... Pin
min_2_max15-Aug-07 23:11
membermin_2_max15-Aug-07 23:11 

I'm looking for a splash implementation that is similar to that of Photoshop.
The main function I need is to change the text on the splash is changeable at runtime.

After a while, I realized that a correct way to this is an implementation based on a dialog.
It's what I need.

One question here:

I'm using it in a Doc/View program instead of a dialog program, so I don't want the program
to exit, as the demo program, on the timer message, but just close the transparent dialog,
I change the code in CTransparentDialogDlg::OnTimer(UINT nIDEvent) from



but the splash just don't close as anticipated. Why?

Thanks again.

GeneralRe: Good, It's what I'm looking for ... Pin
min_2_max15-Aug-07 23:14
membermin_2_max15-Aug-07 23:14 
GeneralRe: Good, It's what I'm looking for ... Pin
min_2_max15-Aug-07 23:40
membermin_2_max15-Aug-07 23:40 
GeneralGetting an Error Pin
simhadri13-Mar-06 23:29
membersimhadri13-Mar-06 23:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170118.1 | Last Updated 4 Dec 2002
Article Copyright 2002 by Nic Wilson
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid