|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
IntroductionI always wondered how to make a window transparent so that all the clicks on the window filter down to the window underneath .At last Microsoft has provided support in Windows Me and 2000 for creating transparent windows . And alpha-blending (This support is not there in previous platforms). In previous platforms (Win 9x ) one could use So Lets get on with the code . The support added by Microsoft Lies in a new function named SetWindowLong (hWnd , GWL_EXSTYLE ,
GetWindowLong (hWnd , GWL_EXSTYLE ) | WS_EX_LAYERED ) ;
Here The # define WS_EX_LAYERED 0x80000 After you have done this you can now call the magic function HWND hWnd=this->m_hWnd; typedef DWORD (WINAPI *PSLWA)(HWND, DWORD, BYTE, DWORD); PSLWA pSetLayeredWindowAttributes; HMODULE hDLL = LoadLibrary ("user32"); pSetLayeredWindowAttributes = (PSLWA) GetProcAddress(hDLL,"SetLayeredWindowAttributes"); if (pSetLayeredWindowAttributes != NULL) { /* * Second parameter RGB(255,255,255) sets the colorkey * to white LWA_COLORKEY flag indicates that color key * is valid LWA_ALPHA indicates that ALphablend parameter * (factor) is valid */ pSetLayeredWindowAttributes (hWnd, RGB(255,255,255), factor, LWA_COLORKEY|LWA_ALPHA); } The Code first loads the library User32.lib which defines the Color KeysColor Keys are a way of telling the Windows that which color to take as being transparent. Say if you set the Color Key to Blue and select Alpha Blend FactorAlpha Blend factor that is the third parameter in NOTE : You may have to define the two flags #define LWA_COLORKEY 1 #define LWA_ALPHA 2 in case of a compiler error. When Window is transparent all the clicks on the window go down to the window underneath it . The SampleThe Sample program provided is very simple. It sets the Layered attribute of windows in AcknowledgementI really am thankful to all the articles written on transparent windows that I read before writing this one for CodeProject.
|
||||||||||||||||||||||