Program the translucent EFFECT OF THE FORM

Source: Internet
Author: User
Program Implementation form translucent effect Author: Luo Yun Release Date: 2001/03/16
 
Abstr:
As you all know, Windows 2000 supports fade-in and fade-out forms. How can we make our applications have this effect? The answer to this question is provided below.

Body:  



Program the translucent EFFECT OF THE FORM

  

If you are not using Windows2000 + Delphi programming, I don't want to waste your time. If yes, continue.
As you all know, Windows 2000 supports fade-in and fade-out forms. How can we make our applications have this effect? Two days ago to study the formcontainer form display effect (Note: formcontainer is a powerful Delphi special effects processing controls, interested friends can access the http://www.billeniumsoft.com/), high people tell, the core API function is setlayeredwindowattributes.
To achieve the fade-in and fade-out effect, you need to achieve the adjustable transparent effect of the window. For traditional Windows applications to achieve transparent results, generally they need to process the wm_paint message of their own windows. The programmer needs getdc to obtain the HDC of the screen, call the bitblt function to copy the area to be overwritten on the screen to the tbitmap object in the memory. Then, modify the values of rgbtred, rgbtgreen, and rgbtblue on the scanline two-dimensional array of the tbitmap pixel by pixel. Oh, it's too much trouble.
The Windows API library finally provides support for translucent forms (although not perfect ). To achieve a translucent window effect, you must first add the ws_ex_layered extension attribute to the created window. This is a new window extension attribute. delphi5 does not define the corresponding constants and setlayeredwindowattributes functions, we need to manually declare it.

Function setlayeredwindowattributes (handle: hwnd;
Colorkey: colorref; Alpha: byte; flags: DWORD): Boolean; stdcall; External 'user32. dll ';

Const
Ws_ex_layered = $80000;
Lwa_alpha = 2;

Call the getwindowlong function to obtain the extended properties of the current window, and call the setwindowlong function to add the extended properties of the new ws_ex_layered window.

Procedure tform1.formcreate (Sender: tobject );
Begin
Setwindowlong (handle, gwl_exstyle, getwindowlong (handle, gwl_exstyle) or ws_ex_layered );
End;

Now our window can call the setlayeredwindowattributes function. By setting the Alpha parameter of this function, we can see the changes in the window effect.

Procedure tform1.button1click (Sender: tobject );
Begin
Setlayered;wattributes (form1.handle, 0,180, lwa_alpha );
End;

The following VCL Control Code encapsulates the setlayeredwindowattributes function and dynamically changes the alphavalue value during programming. Then you can see the transparent window effect. The control shields the display effect during the design period. If you are willing to change the display effect to visible, you may not be able to find the form you want to design.

Unit Tranform; {dragonpc 2001.2.21}

Interface

Uses
Windows, messages, sysutils, classes, graphics, controls, forms;

Type
Ttranform = Class (tcomponent)
Private
Falphavalue: integer;
Fparentformhandle: hwnd;
Procedure setfalphavalue (ALPHA: integer );
Protected
Procedure updatedisplay;
Public
Constructor create (aowner: tcomponent); override;
Published
Property alphavalue: integer read falphavalue write setfalphavalue;
End;

Procedure register;

Function setlayeredwindowattributes (handle: hwnd; colorkey: colorref;
ALPHA: byte; flags: DWORD): Boolean; stdcall; External 'user32. dll ';

Implementation

Procedure register;
Begin
Registercomponents ('standard', [ttranform]);
End;

Procedure ttranform. setfalphavalue (ALPHA: integer );
Begin
If (alpha> = 0) and (alpha <256) then begin
Falphavalue: = Alpha;
Updatedisplay ();
End;
End;

Procedure ttranform. updatedisplay;
Begin
If (csdesigning in componentstate) Then exit;
Setlayeredwindowattributes (fparentformhandle, 0, falphavalue, 2 );
End;

Constructor ttranform. Create (aowner: tcomponent );
Begin
Inherited;
If (csdesigning in componentstate) Then exit;
Falphavalue := 255;
Fparentformhandle: = tform (aowner). Handle;
Setwindowlong (fparentformhandle,
Gwl_exstyle,
Getwindowlong (fparentformhandle, gwl_exstyle) or ws_ex_layered );
End;

End.

Thank you for your patience to read this article, this article is purely written in order to earn China-pub "counterfeit currency" purpose, in case you have any questions, welcome to the dragonpc@21cn.com, thank you.


Member name of the author: dragonpc

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.