Click here to Skip to main content
6,596,602 members and growing! (23,256 online)
Email Password   helpLost your password?
Desktop Development » Dialogs and Windows » General     Intermediate License: The Code Project Open License (CPOL)

MFC Transparent CDialog Demo

By Nic Wilson

A transparent dialog
VC6, VC7Win2K, WinXP, MFC, Dev
Posted:3 Dec 2002
Views:104,310
Bookmarked:59 times
Announcements
Loading...
 
Search    
Advanced Search
Add to IE Search
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
34 votes for this article.
Popularity: 6.55 Rating: 4.28 out of 5
2 votes, 5.7%
1
1 vote, 2.9%
2
2 votes, 5.7%
3
5 votes, 14.3%
4
25 votes, 71.4%
5

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)

About the Author

Nic Wilson


Member

Occupation: Web Developer
Location: Australia Australia

Other popular Dialogs and Windows articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 22 of 22 (Total in Forum: 22) (Refresh)FirstPrevNext
Generalbuttons Pinmemberbasculo12:28 29 Apr '09  
GeneralQuestion on the way you exit application Pinmemberandyluu9:30 19 Jan '09  
GeneralRe: Question on the way you exit application PinmemberNic Wilson11:50 19 Jan '09  
Generalit's great. PinmemberMohamad Kaifi1:19 8 May '08  
GeneralRe: it's great. PinmemberNic Wilson11:54 19 Jan '09  
GeneralGood, It's what I'm looking for ... Pinmembermin_2_max23:11 15 Aug '07  
GeneralRe: Good, It's what I'm looking for ... Pinmembermin_2_max23:14 15 Aug '07  
GeneralRe: Good, It's what I'm looking for ... Pinmembermin_2_max23:40 15 Aug '07  
GeneralGetting an Error Pinmembersimhadri23:29 13 Mar '06  
GeneralRe: Getting an Error PinmemberCode Incomplete...18:41 11 Apr '06  
Generalhi,greate, but can it is used with ws_child window? Pinmemberwwx18:03 13 Sep '05  
Generalcapture hiden window Pinmemberjags_vc20:36 16 Feb '05  
Generalproblem with the position of the window PinsussMarco Randazzo4:31 14 Sep '04  
GeneralTry this... Pinmemberel_rata9:57 15 Jan '04  
GeneralWonderful ! PinmemberLeeZi15:35 1 Sep '03  
GeneralGreat!! But is it possible?? PinmemberAWebDude15:24 12 Mar '03  
GeneralImage.bmp is not provided with the zip PinmemberShanhaz0:51 12 Mar '03  
GeneralRe: Image.bmp is not provided with the zip PinmemberNic Wilson12:18 12 Mar '03  
GeneralNice! Pinmembermanos_crete6:55 28 Dec '02  
GeneralRe: Nice! PinmemberThe Yariv23:03 22 Jan '07  
GeneralRe: Nice! Pinmembermanos_crete13:06 27 Jan '07  
GeneralThanks, but... Pinmemberzarzor18:31 4 Dec '02  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 3 Dec 2002
Editor: Chris Maunder
Copyright 2002 by Nic Wilson
Everything else Copyright © CodeProject, 1999-2009
Web21 | Advertise on the Code Project