svět, kde se rodí nová budoucnost   
 
Delphi headDelphi Tips

SemiTransparent Window

Here is a example how you can make your forms/dialogs make semi transparent, the value of TR_BLEND decides the activety of blending your forms or dialogs.

By value 254  is no blending, by value zero it is almost invisible. 254 should be the maximum value to use and 0 the minimum. It was tested on Windows XP only. It can give great effect on your program when you work with images. Hope its usefull.

{some constants & global variables}
CONST TRBLEND_DEFAULT     = 254;
VAR   TR_BLEND  : INTEGER = TRBLEND_DEFAULT;
      RGB_RED   : INTEGER =
0;
      RGB_GREEN : INTEGER =
0;
      RGB_BLUE  : INTEGER =
0;

{Transparent Code for forms, XP /2000}
const
 
BLEND_COLOR     = $00000001;
  BLEND_ALPHA     =
$00000002;

{the procedure for blending dialogs/forms}
procedure DMBlend(Handle : THandle; Blend,
                   rgbred,rgbgreen,rgbblue:Integer);
var
  
ExtStyle : LongInt;
begin
 
ExtStyle := GetWindowLong(Handle, GWL_EXSTYLE);
  SetWindowLong(Handle, GWL_EXSTYLE, ExtStyle
or
                                       
WS_EX_LAYERED);
  SetLayeredWindowAttributes(Handle,
               RGB(rgbred,rgbgreen,rgbblue),
               TR_BLEND, BLEND_ALPHA
or BLEND_COLOR);
end;

{calling the procedure}
DMBlend(form.Handle,TR_BLEND,
                           RGB_RED,RGB_GREEN,RGB_BLUE);

 

Back to Index of Tips

 

 

Send mail to radek.novak@infojet.cz with questions or comments about this web site.
Copyright © 1999-2002 Infojet.cz
Last modified: 26.07.2002