Click here to Skip to main content
Licence CPOL
First Posted 5 Aug 2006
Views 62,283
Downloads 818
Bookmarked 43 times

CGlassDialog

By | 11 Aug 2006 | Article
This is a simple class that makes transparent dialog boxes rise more smoothly.

Sample Image - CGlassDialog.jpg

Introduction

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

typedef BOOL(WINAPI *SLWA)(HWND, COLORREF, BYTE, DWORD); 

and then, you can use this code:

SLWA pSetLayeredWindowAttributes = NULL;  
HINSTANCE hmodUSER32 = LoadLibrary("USER32.DLL"); 
pSetLayeredWindowAttributes =(SLWA)GetProcAddress(hmodUSER32, 
           "SetLayeredWindowAttributes");
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!! :)

License

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)

Member

Hi, I'm Youngman Park~

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
Questionyou rock buddy Pinmemberomkarpardeshi1233:55 7 Dec '11  
GeneralWell done PinmemberDr.Luiji22:13 29 Aug '07  
GeneralThank's PinmemberVaga150510:14 5 Dec '06  
GeneralAmazing Pinmembercodesen19:54 5 Nov '06  
GeneralA suggestion/request PinmemberPaolo Vernazza10:50 16 Aug '06  
GeneralRe: A suggestion/request PinmemberYoungman Park13:20 16 Aug '06  
QuestionGood Job: two more questions PinmemberGianniGP0:44 16 Aug '06  
AnswerRe: Good Job: two more questions PinmemberYoungman Park12:40 16 Aug '06  
GeneralRe: Good Job: two more questions PinmemberGianniGP23:11 16 Aug '06  
AnswerRe: Good Job: two more questions PinmemberYoungman Park10:14 17 Aug '06  
GeneralRe: Good Job: two more questions PinmemberGianniGP22:57 17 Aug '06  
AnswerRe: Good Job: two more questions PinmemberYoungman Park22:05 19 Aug '06  
GeneralRe: Good Job: two more questions PinmemberGianniGP0:22 20 Aug '06  
GeneralRe: Good Job: two more questions PinmemberAnt Htoo Naing16:44 2 Aug '07  
Generalsolution to initial flicker Pinmemberjnapier10:46 10 Aug '06  
GeneralRe: solution to initial flicker PinmemberYoungman Park15:51 10 Aug '06  
Generalcool Pinmemberdavidoff2:58 8 Aug '06  
GeneralRe: cool PinmemberYoungman Park3:07 8 Aug '06  
Generalcreative [modified] Pinmemberpb9621:11 7 Aug '06  
GeneralRe: creative [modified] PinmemberYoungman Park3:07 8 Aug '06  
QuestionYour Project Pinmembercoronys20:32 7 Aug '06  
AnswerRe: Your Project PinmemberYoungman Park3:04 8 Aug '06  
GeneralRe: Your Project Pinmembercoronys3:41 8 Aug '06  
AnswerRe: Your Project [modified] PinmemberYoungman Park3:55 8 Aug '06  
GeneralRe: Your Project Pinmembercoronys5:48 8 Aug '06  

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

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

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120517.1 | Last Updated 12 Aug 2006
Article Copyright 2006 by Youngman Park
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid