Make the form with a transparent effect API

xiaoxiao2021-03-06  70

I. Background FlashGet's transparent effect, everyone envy. Traditional Windows applications want to achieve translucent effects, generally need to handle our window's WM_Paint message window, very troublesome. Now, setlayeredWindowAttributes is new API, Win2000 Support above, it enables the form to have a transparent effect. I have been searching for Google. Introducing the article in SetLayeredWindowAttributes. Most of the articles of Delphi and VB. Fortunately, the VC is found, but the vc's IDE said I said SetlayeredWindowAttribute is not defined! Later, I thought I should be my SDK didn't upgrade. So I am searching "* .h" file "setlayeredWindowattribute" in the VC installation directory, there is no. What should I do? Upgrade SDK. I went to the Microsoft website. The new SDK has more than 200 M M. (larger after decompression), the poor my hard drive does not have a partition greater than 200m! What to do, such a fun API gives it: (Disappointment) I suddenly thought of the way I didn't open the API. This is a system support, but I have no API of my SDK, I will try him when doing Windows Undefled API!

Sample code running renderings

Second, briefly introduce setlayeredWindowAttributes: (see MSDN)

Bool setlayeredWindowAttributes

HWND HWND, // Handle to the Layered Window

ColorRef CRKEY, / / ​​SPECIFIES THE Color Key

Byte Balpha, // Value for the Blend Function

DWORD DWFLAGS // Action

Windows NT / 2000 / XP: Included in Windows 2000 and Later.

Windows 95/98 / me: unsupported.

Header: declared in winuser.h; include windows.h.

Library: USE User32.lib.

Some constants:

WS_EX_LAYERED = 0x80000;

LWA_ALPHA = 0x2;

LWA_COLORKEY = 0x1

Where dwflags have lwa_alpha and lwa_colorKey

LWA_ALPHA is set, the transparency is determined by Balpha.

If LWA_COLORKEY is set, specify that the transparent color is CRKEY, and other colors are displayed normally.

Note: To make the form have a transparent effect, you must first have a WS_EX_LAYERED extension attribute (the old SDK is not there).

Third, example code:

Add in OnInitDialog ():

/ / Add WS_EX_LAYED extension attribute

SetWindowlong (this-> getsafehwnd (), gwl_exstyle,

GetWindowlong (this-> getsafehwnd (), gwl_exstyle) ^ 0x80000);

Hinstance hinst = loadingLibrary ("user32.dll");

IF (hinst)

{

Typedef Bool (WinApi * Myfunc) (HWND, ColorRef, Byte, DWORD);

Myfunc fun = null;

// get the setlayeredWindowAttributes function pointer

Fun = (MyFunc) GetProcaddress (Hinst, "SetlayeredWindowAttributes");

IF (fun) Fun (this-> getsafehwnd (), 0, 128, 2);

Freelibrary (HINST);

}

Hey! If you install the latest SDK, you don't have to be so troublesome!

How, good effect! Slightly modification can also make a fade out of the fade in the fade. Pay attention to the third parameter (128) Don't get too small, 0 words are completely transparent, you can't find the form! Little experience It is fast. I hope to help beginners. If there is anything wrong, welcome to correct.

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

New Post(0)