Click here to Skip to main content
15,879,613 members
Articles / Desktop Programming / MFC
Article

MFC Transparent CDialog Demo

Rate me:
Please Sign up or sign in to vote.
4.61/5 (39 votes)
3 Dec 2002CPOL2 min read 182.7K   8.6K   87   23
A transparent dialog

Sample Image - transparentdialog.gif

Introduction

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.

History

V1.0 initial release 27th November 2002

License

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


Written By
Web Developer
Australia Australia
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneraliY undefined. Pin
Joel Brockman9-Feb-11 11:21
Joel Brockman9-Feb-11 11:21 
Generalbuttons Pin
basculo29-Apr-09 11:28
basculo29-Apr-09 11:28 
GeneralQuestion on the way you exit application Pin
andyluu19-Jan-09 8:30
andyluu19-Jan-09 8:30 
GeneralRe: Question on the way you exit application Pin
Nic Wilson19-Jan-09 10:50
Nic Wilson19-Jan-09 10:50 
Generalit's great. Pin
Mohamad Kaifi8-May-08 0:19
Mohamad Kaifi8-May-08 0:19 
GeneralRe: it's great. Pin
Nic Wilson19-Jan-09 10:54
Nic Wilson19-Jan-09 10:54 
There are many good books on MFC the eaisest to follow would be the "Osborne" "The Complete Reference" series they have some books on Visual C++ which have some good MFC examples. I use the MSDN library articles quite a lot, just looking at each MFC class and them implementing the ones I want or need.

nicw
MSN nicwilson@hotmail.com
GeneralGood, It's what I'm looking for ... Pin
min_2_max15-Aug-07 22:11
min_2_max15-Aug-07 22:11 
GeneralRe: Good, It's what I'm looking for ... Pin
min_2_max15-Aug-07 22:14
min_2_max15-Aug-07 22:14 
GeneralRe: Good, It's what I'm looking for ... Pin
min_2_max15-Aug-07 22:40
min_2_max15-Aug-07 22:40 
GeneralGetting an Error Pin
simhadri13-Mar-06 22:29
simhadri13-Mar-06 22:29 
GeneralRe: Getting an Error Pin
Code Incomplete...11-Apr-06 17:41
Code Incomplete...11-Apr-06 17:41 
Questionhi,greate, but can it is used with ws_child window? Pin
William.Wang13-Sep-05 17:03
William.Wang13-Sep-05 17:03 
Generalcapture hiden window Pin
Jagdish Vasani16-Feb-05 19:36
Jagdish Vasani16-Feb-05 19:36 
Generalproblem with the position of the window Pin
Marco Randazzo14-Sep-04 3:31
sussMarco Randazzo14-Sep-04 3:31 
GeneralTry this... Pin
el_rata15-Jan-04 8:57
el_rata15-Jan-04 8:57 
GeneralWonderful ! Pin
Member 917961-Sep-03 14:35
Member 917961-Sep-03 14:35 
QuestionGreat!! But is it possible?? Pin
AWebDude12-Mar-03 14:24
AWebDude12-Mar-03 14:24 
GeneralImage.bmp is not provided with the zip Pin
Shanhaz11-Mar-03 23:51
Shanhaz11-Mar-03 23:51 
GeneralRe: Image.bmp is not provided with the zip Pin
Nic Wilson12-Mar-03 11:18
Nic Wilson12-Mar-03 11:18 
GeneralNice! Pin
manos_crete28-Dec-02 5:55
manos_crete28-Dec-02 5:55 
GeneralRe: Nice! Pin
The Yariv22-Jan-07 22:03
The Yariv22-Jan-07 22:03 
GeneralRe: Nice! Pin
manos_crete27-Jan-07 12:06
manos_crete27-Jan-07 12:06 
GeneralThanks, but... Pin
zarzor4-Dec-02 17:31
zarzor4-Dec-02 17:31 

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.