Programming to implement the translucent effect of the form

zhaozj2021-02-11  190

Programming the form of translucent effect of: Luo Qiang Published: 2001/03/16

Thesis:

Everyone knows that Windows 2000 supports fade-in-fade form display effect. How to make your application also have this effect? This problem is made by this problem.

text:

Programming to implement the translucent effect of the form If you are not using Windows2000 Delphi programming, I don't want to waste your time. If so, please continue. Everyone knows that Windows 2000 supports fade-in-fade form display effect. How to make your application also have this effect? The previous two days of studying the FormContainer's FORM display effect (Note: formcontainer is a powerful Delphi special effects control control, interested friends can access http://www.billeniumsoft.com/), the high person is told that the core API function is SetlayeredWindowAttributes. To achieve fade in fade out, you need to implement the adjustable transparent effect of the window. The traditional Windows application wants to achieve a transparent effect. Generally, the WM_PAINT message that needs to be handled, the programmer needs the getDC to get the HDC of the screen, call the bitblt function to copy the screen to the memory of the memory to the Tbitmap object, then Modify the RGBTRED, RGBTGREEN and RGBTBLUE values ​​for this Tbitmap's Scanline 2D array element pixel. Heaven, it is too much trouble. The Windows2000's API library finally provides a translucent form display effect support (although not very perfect). To achieve a translucent window effect, first add a WS_EX_LAYERED extension attribute to the created window, which is a new window extension attribute, and Delphi5 does not define the corresponding constant and setlayeredWindowAttributes function, we need manual declaration. function SetLayeredWindowAttributes (Handle: HWND; COLORKEY: COLORREF; Alpha: BYTE; Flags: DWORD): Boolean; stdcall; external 'USER32.DLL'; Const WS_EX_LAYERED = $ 80000; LWA_ALPHA = 2; we call GetWindowLong function to get extended attributes of the current window And call the setWindowlong function Add in the new WS_EX_LAYERED window extension attribute. procedure TForm1.FormCreate (Sender: TObject); begin SetWindowLong (Handle, GWL_EXSTYLE, GetWindowLong (Handle, GWL_EXSTYLE) or WS_EX_LAYERED); end; now we can already call SetLayeredWindowAttributes window function, by setting the Alpha parameter of the function, we can See the changes in the window. procedure TForm1.Button1Click (Sender: TObject); begin SetLayeredWindowAttributes (Form1.Handle, 0, 180, LWA_ALPHA); end; VCL control code following encapsulates SetLayeredWindowAttributes function, dynamically changing value during programming AlphaValue, you can see the window Transparent effect.

转载请注明原文地址:https://www.9cbs.com/read-5001.html

New Post(0)