Semi-translucent form

zhaozj2021-02-08  228

The translucent form is not a new effect of Win2000. Any comrades who have used Jinshan Words will find that there is a semi-transparent background option in the screen. This shows that it can achieve a translucent window under Win98. But I still have to talk about the new function setlayeredWindowAttributes in the Win2000 to achieve a translucent form. With this function, you can easily create a translucent form, but use this function to compile after the Win98 is unable to run. SetLayeredWindowAttributes API functions are described below: Function: Transparent Color settings window parameters: SetLayeredWindowAttributes (HWND hwnd, // window handle COLORREF crKey, // specify color values ​​BYTE bAlpha, // DWORD dwFlags // mixing action function values ​​of parameters: HWND: Window handle. When you create a window using the CREATEWINDOWEX function, the window is created by the value specified by WS_EX_LAYERED. After the window is already created, the setWindowlong is changed by the value specified by WS_EX_LAYERED. CRKEY: Points a color value, when the value specifies a transparent color value, when When you create a window, the window will use this value. BALPHA: Mix function. This value is used to describe the opacity of the window. When the Balpha value is 0, the window is completely transparent. When the Balpha value is 255, the window is completely opaque. Dwflags: Specify actions. This parameter can take one or more values. Use it we can create an irregular form. The setLayeredWindowAttributes function API declaration: setLayeredWindowAttributes (hwnd: hwnd; crkey: DWORD; Balpha: Byte; dwflag: dWord): DWORD: Boolean; stdcall; --------- program code 1: const WS_EX_LAYERED = $ 80000; lwa_colorkey = $ 1; lwa_alpha = $ 2; procedure tform1.formcreate (sender: TOBJECT); var l: longint; begin l: = getWindowlong (handle, GWL_EXSTYLE); l: = l Or WS_EX_LAYERED; SetWindowLong (handle, GWL_EXSTYLE, l); SetLayeredWindowAttributes (handle, 180, 120, LWA_ALPHA); end; Still other constants defined as: AC_SRC_ALPHA = $ 1; AC_DST_NO_PREMULT_ALPHA = $ 10; ULW_COLORKEY = $ 1; ulw_alpha = $ 2; ulw_opaque = $ 400; etc. Also see MSDN. Some I haven't figured out, if a comrade is known, please tell me. So how do you achieve a translucent form in Win98? The basic principle is: After the window is displayed, it will get the background image before the window is displayed. Then, filter the background image, and then display the process over the window. . One way is: First, make a transparent form, then add a shape on the form, extend it to full screen, set the Mode property of Shape to pmmask, Pen's style property is set to psclear, last Change the COLOR attribute of Brush. Because there is no API support, Win9X can only simulate, the effect is not very good, just like the word window, background change in the background change, and the form is constant. But we can use the Timer control to solve the problem of the form's refresh rate and time update.

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

New Post(0)