![]() |
|
||||||||||||||
| | 网站首页 | 数据库教程 | web编程 | 服务器 | 程序设计 | | ||
|
||
|
||||||
| 半透明或过滤某种颜色的实现 | ||||||
作者:佚名 文章来源:不详 点击数: 更新时间:2007-9-12 ![]() |
||||||
|
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. 一些常量: WS_EX_LAYERED = 0x80000; LWA_ALPHA = 0x2; LWA_COLORKEY=0x1 其中dwFlags有LWA_ALPHA和LWA_COLORKEY。
注:要使使窗体拥有透明效果,首先要有WS_EX_LAYERED扩展属性(旧sdk也没有的)。 例子代码: 在OnInitDialog()加入: //加入WS_EX_LAYERED扩展属性 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; //取得SetLayeredWindowAttributes函数指针 fun=(MYFUNC)GetProcAddress(hInst, "SetLayeredWindowAttributes"); if(fun)fun(this->GetSafeHwnd(),0,128,2); FreeLibrary(hInst); } 第二种例子代码 在.h中加入 #define LWA_COLORKEY 0x00000001 #define WS_EX_LAYERED 0x00080000 typedef BOOL (WINAPI *lpfnSetLayeredWindowAttributes)(HWND hWnd, COLORREF crKey, BYTE bAlpha, DWORD dwFlags); lpfnSetLayeredWindowAttributes SetLayeredWindowAttributes; 在.cpp中 COLORREF maskColor=RGB(0X80,0XC0,0XFF); HMODULE hUser32 = GetModuleHandle("user32.dll"); SetLayeredWindowAttributes = (lpfnSetLayeredWindowAttributes)GetProcAddress(hUser32,"SetLayeredWindowAttributes"); SetWindowLong(GetSafeHwnd(), GWL_EXSTYLE, GetWindowLong(GetSafeHwnd(), GWL_EXSTYLE)|WS_EX_LAYERED); SetLayeredWindowAttributes(GetSafeHwnd(), maskColor, 255, LWA_COLORKEY); FreeLibrary(hUser32); 本文来源:http://blog.csdn.net/cyrx2003/archive/2007/08/23/1756783.aspx
|
||||||
| 文章录入:admin 责任编辑:admin | ||||||
| 【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口】 | ||||||
| 网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!) |
| | 设为首页 | 加入收藏 | 联系站长 | 友情链接 | 版权申明 | 网站公告 | 网站地图 | 管理登录 | | |||
|