Click here to Skip to main content
11,923,517 members (60,941 online)
Click here to Skip to main content
Add your own
alternative version


48 bookmarked


, 11 Aug 2006 CPOL
Rate this:
Please Sign up or sign in to vote.
This is a simple class that makes transparent dialog boxes rise more smoothly.

Sample Image - CGlassDialog.jpg


Before introducing this class, I want you to know my English is not very good. And, this is my first article. I've always got a lot of help from this site, so I really wanted to write an article and give back to the community.

Anyway, this is a simple class that makes transparent dialog boxes rise more smoothly. The reason why I made this is.. I've been making a program that has transparent windows. I thought if the windows could rise in more smoothly, it would be better visually. And I made up my mind to make this class.

How to make this??

It's so simple, I use an OnTimer() for the smooth rising.

First, you must declare this in your .h file:

#define WS_EX_LAYERED   0x00080000
#define LWA_COLORKEY    0x00000001
#define LWA_ALPHA       0x00000002
#define ULW_COLORKEY    0x00000001
#define ULW_ALPHA       0x00000002
#define ULW_OPAQUE      0x00000004


and then, you can use this code:

SLWA pSetLayeredWindowAttributes = NULL;  
HINSTANCE hmodUSER32 = LoadLibrary("USER32.DLL"); 
pSetLayeredWindowAttributes =(SLWA)GetProcAddress(hmodUSER32, 
SetWindowLong(m_hWnd, GWL_EXSTYLE, 
           GetWindowLong(m_hWnd, GWL_EXSTYLE) | WS_EX_LAYERED);
pSetLayeredWindowAttributes(m_hWnd, 0, (255 * m_nGlass) / 100, LWA_ALPHA);

In this code, m_nGlass is the rating of transparency so you can set this from 0 to 100. (If you set m_nGlass to 0, the dialog box will be perfectly transparent. If you set m_nGlass to 100, the dialog box will not be transparent at all.)

I've used this point. OnTimer() is the event function of WM_TIMER, so it makes executes the function in regular intervals.

in OnTimer(), you change the value of m_nGlass:

(m_nGlass >= 70) ? ReleaseTimer() : m_nGlass += m_nStepUnit; 

How to use this??

If you want to use this class, first, add GlassiDialog.h and GlassDialog.cpp into your project and #include GlassDialog.h where needed. Then, inherit the CGlassDialog class in your dialog class. (I.e., you should change the base class in your dialog from CDialog to CGlassDialog. Just go to your .cpp, .h files and use the "Replace" feature of your code editor to replace all CDialog with CGlassDialog.)

Now, that's all! Your dialog class is ready to go. When you create your dialog object, you will be able to see a smooth rising dialog box.

Thank you for reading my article!! Smile | :)


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


About the Author

Youngman Park
Software Developer
Korea (Republic Of) Korea (Republic Of)
No Biography provided

You may also be interested in...

Comments and Discussions

Questionyou rock buddy Pin
omkarpardeshi1237-Dec-11 4:55
memberomkarpardeshi1237-Dec-11 4:55 
GeneralWell done Pin
Dr.Luiji29-Aug-07 23:13
memberDr.Luiji29-Aug-07 23:13 
GeneralThank's Pin
Vaga15055-Dec-06 11:14
memberVaga15055-Dec-06 11:14 
GeneralAmazing Pin
codesen5-Nov-06 20:54
membercodesen5-Nov-06 20:54 
GeneralA suggestion/request Pin
Paolo Vernazza16-Aug-06 11:50
memberPaolo Vernazza16-Aug-06 11:50 
GeneralRe: A suggestion/request Pin
Youngman Park16-Aug-06 14:20
memberYoungman Park16-Aug-06 14:20 
QuestionGood Job: two more questions Pin
GianniGP16-Aug-06 1:44
memberGianniGP16-Aug-06 1:44 
AnswerRe: Good Job: two more questions Pin
Youngman Park16-Aug-06 13:40
memberYoungman Park16-Aug-06 13:40 
GeneralRe: Good Job: two more questions Pin
GianniGP17-Aug-06 0:11
memberGianniGP17-Aug-06 0:11 
AnswerRe: Good Job: two more questions Pin
Youngman Park17-Aug-06 11:14
memberYoungman Park17-Aug-06 11:14 
I can understand your saying. If you didn't use MFC, you can't use this class 'CGlassDialog'. However this function is possible to use in Win32 Program as well. Just you should do coding by yourself but it's not difficult. Actually, this class is not necessary, just the reason why I made this is for a convenience of coding.

If you used Win32 for Dialog, probably you made any DialogProc function. If so, you can describe this function into there. For example, you can make any message case like WM_CREATE, WM_TIMER and so on.. and Into there, you can describe the function that make Dialog be transparent smoothly.

See the 'GlassClass.h' file. There are just 2 Message functions.

afx_msg void OnTimer(UINT nIDEvent);
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);

This 2 functions can be described as WM_CREATE and WM_TIMER in Win32 any DialogProc function.

Like this

switch( iMessage )

case WM_TIMER:

Anyway, Refer to the 2 functions in 'GlassDialog.cpp' and Do coding. Probably you can do easily I think.


If you can't understand my explain, tell me again. As I said, my English is really not good. Dead | X|

GeneralRe: Good Job: two more questions Pin
GianniGP17-Aug-06 23:57
memberGianniGP17-Aug-06 23:57 
AnswerRe: Good Job: two more questions Pin
Youngman Park19-Aug-06 23:05
memberYoungman Park19-Aug-06 23:05 
GeneralRe: Good Job: two more questions Pin
GianniGP20-Aug-06 1:22
memberGianniGP20-Aug-06 1:22 
GeneralRe: Good Job: two more questions Pin
Ant Htoo Naing2-Aug-07 17:44
memberAnt Htoo Naing2-Aug-07 17:44 
Generalsolution to initial flicker Pin
jnapier10-Aug-06 11:46
memberjnapier10-Aug-06 11:46 
GeneralRe: solution to initial flicker Pin
Youngman Park10-Aug-06 16:51
memberYoungman Park10-Aug-06 16:51 
Generalcool Pin
davidoff8-Aug-06 3:58
memberdavidoff8-Aug-06 3:58 
GeneralRe: cool Pin
Youngman Park8-Aug-06 4:07
memberYoungman Park8-Aug-06 4:07 
Generalcreative [modified] Pin
pb967-Aug-06 22:11
memberpb967-Aug-06 22:11 
GeneralRe: creative [modified] Pin
Youngman Park8-Aug-06 4:07
memberYoungman Park8-Aug-06 4:07 
QuestionYour Project Pin
coronys7-Aug-06 21:32
membercoronys7-Aug-06 21:32 
AnswerRe: Your Project Pin
Youngman Park8-Aug-06 4:04
memberYoungman Park8-Aug-06 4:04 
GeneralRe: Your Project Pin
coronys8-Aug-06 4:41
membercoronys8-Aug-06 4:41 
AnswerRe: Your Project [modified] Pin
Youngman Park8-Aug-06 4:55
memberYoungman Park8-Aug-06 4:55 
GeneralRe: Your Project Pin
coronys8-Aug-06 6:48
membercoronys8-Aug-06 6:48 

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
Web03 | 2.8.151125.3 | Last Updated 12 Aug 2006
Article Copyright 2006 by Youngman Park
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid