[Reserved] Realization of Transparent Forms

xiaoxiao2021-03-05  39

This article is reproduced from VCROAD, author Nanhai Zhaoxi. First, the background of the transparent effect of the background. The traditional Windows application wants to achieve a translucent effect. Generally speaking, the WM_PAINT message window that needs to handle your window is very troublesome. Now it is good. SetlayeredWindowAttributes is a new API of Windows. It supports Win2000, which enables the form to have a transparent effect. I have a Google search, introducing the article of SetLayeredWindowAttributes. Most of the articles of Delphi and VB. Finely found a VC, After the law, VC's IDE said that I setlayeredWindowAttribute did not define! Later, I thought I should be my SDK didn't upgrade. So I am searching "setlayeredWindowAttributes" in the VC installation directory, there is no. What should I do? Upgrade SDK Let's go to Microsoft's website, there will be more than 200 M M in the core SDK (larger after decompression), the poor my hard drive does not have a partition greater than 200m! What to do, this fun API give I don't want to use: (I am disappointed, I suddenly thought of the method of using the unapproved API. This is a system support, but the API, but the API, I don't have public API, I will try it out! Second, briefly introduce it 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 has LWA_ALPHA and LWA_COL ORKEY LWA_ALPHA is set, the transparency is determined by Balpha. LWA_COLORKEY is set, then specify the transparent color to crkey, other colors are displayed normally. Note: To make the form a transparent effect, you must have a WS_EX_LAYERED extension attribute ( Old SDK is not there). 3, example code: In OnInitdialog () Add: // Add WS_EX_LAYERED Extended Properties SetWindowlong (this-> getsafehwnd (), gwl_exstyle, getWindowlong (this-> getsafehwnd (), gwl_exstyle) ^ 0x80000); HINSTANCE hInst = LoadLibrary ( "User32.DLL"); if (hInst) {typedef BOOL (WINAPI * MYFUNC) (HWND, COLORREF, BYTE, DWORD); MYFUNC fun = NULL; // function pointer SetLayeredWindowAttributes made fun = (MYFUNC) GetProcaddress (Hinst, "SetlayeredWindowAttributes"); if (fun) Fun (this-> getsafehwnd (), 0, 128, 2); FreeElibrary (HinSt);

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

New Post(0)