Board index » cppbuilder » how can i do the window transparent?

how can i do the window transparent?


2003-07-21 05:04:03 PM
cppbuilder88
How can change the alpha of a window from 0 (perfect transparent) to 100
(perfect opaque) in a time of 4 seconds?
that is:
0?sec (0%) - 1?sec (25%) - 2?sec (50%) - 3?sec (75%) - 4?sec
(100%)
 
 

Re:how can i do the window transparent?

b wrote:
Quote
How can change the alpha of a window from 0 (perfect transparent) to
100 (perfect opaque) in a time of 4 seconds?
that is:

0?sec (0%) - 1?sec (25%) - 2?sec (50%) - 3?sec (75%) -
4?sec (100%)
Add a TTimer component with an interval of 1000.
On the timer event, call MakeWndTrans from the code below:
#ifndef WS_EX_LAYERED
#define WS_EX_LAYERED 0x00080000
#define LWA_COLORKEY 0x00000001
#define LWA_ALPHA 0x00000002
#endif // ndef WS_EX_LAYERED
// Preparation for the function we want to import from USER32.DLL
typedef BOOL (WINAPI *lpfnSetLayeredWindowAttributes)(HWND hWnd, COLORREF
crKey,
BYTE bAlpha, DWORD
dwFlags);
lpfnSetLayeredWindowAttributes m_pSetLayeredWindowAttributes;
BOOL MakeWndTrans(HWND hWnd, int nAlpha=10)
{
// Here we import the function from USER32.DLL
HMODULE hUser32 = GetModuleHandle("USER32.DLL");
m_pSetLayeredWindowAttributes =
(lpfnSetLayeredWindowAttributes)GetProcAddress(hUser32,
"SetLayeredWindowAttributes");
// If the import did not succeed, make sure your app can handle it!
if (NULL == m_pSetLayeredWindowAttributes)
return FALSE; //Bail out!!!
// Check the current state of the dialog, and then add the WS_EX_LAYERED
attribute
SetWindowLong(hWnd, GWL_EXSTYLE, GetWindowLong(hWnd, GWL_EXSTYLE) |
WS_EX_LAYERED);
m_pSetLayeredWindowAttributes(hWnd, 0, (255 / 100) *(100-nAlpha),
LWA_ALPHA);
return TRUE;
}
Jos Branders
 

Re:how can i do the window transparent?

"b" <borland.public.cppbuilder.vcl.components.using>wrote in message
Quote
How can change the alpha of a window from 0 (perfect
transparent) to 100 (perfect opaque) in a time of 4 seconds?
If you are using BCB6, TForm has AlphaBlend and AlphaBlendValue properties.
You can set AlphaBlend to true and then use a TTimer to adjust the
AlphaBlendValue between 0 (transparent) and 255 (opaque).
Note, however, that such an effect would only work under Win2K and XP,
though. Other Windows OSs do not support what you are asking for.
Gambit
 

{smallsort}

Re:how can i do the window transparent?

When i must use an effect working exclusivly under WinXP, how can do to use
the program also in another OS without to show that effect for old OS?
 

Re:how can i do the window transparent?

"b" <borland.public.cppbuilder.vcl.components.using>wrote in message
Quote
When i must use an effect working exclusivly under WinXP,
how can do to use the program also in another OS without
to show that effect for old OS?
If the effect is not supported by the OS than it simply will not be shown.
In the case of the AlphaBlend and AlphaBlendValue properties, they have no
effect under OSs prior to Win2K. TForm already does the necessary version
checking to ensure that the program will still run on OSs that do not
support alpha blending. Any code you write for the properties will simply
not do anything, but it will not cause an error, either.
Gambit