使窗口透明

#define LWA_COLORKEY 0x00000001  // Use color as the transparency color.
#define WS_EX_LAYERED 0x00080000
#define LWA_ALPHA 2   // Use bAlpha to determine the opacity of the layer
typedef BOOL (WINAPI *lpfnSetLayeredWindowAttributes)(HWND hWnd, COLORREF crKey, BYTE bAlpha, DWORD dwFlags);
lpfnSetLayeredWindowAttributes MySetLayeredWindowAttributes;

窗口半透明
HMODULE hUser32 = GetModuleHandle("user32.dll");
MySetLayeredWindowAttributes = (lpfnSetLayeredWindowAttributes)GetProcAddress(hUser32,"SetLayeredWindowAttributes");
if(MySetLayeredWindowAttributes == NULL)
{
 AfxMessageBox("载入系统dll失败,程序即将退出!");
 exit(0);
}

::SetWindowLong(GetSafeHwnd(), GWL_EXSTYLE, GetWindowLong(GetSafeHwnd(), GWL_EXSTYLE) ^ WS_EX_LAYERED);
MySetLayeredWindowAttributes(GetSafeHwnd(), 0,
 130, //这个参数是控制窗口透明的层度, 为0时窗口全透明,包括标题栏. 为255时,不透明
 LWA_ALPHA);//LWA_COLORKEY
FreeLibrary(hUser32);


使对话框窗口的客户区全透明
COLORREF maskColor= 14215660; 这是颜色掩码,与这个颜色相同的将不被显示出来
SetWindowLong(GetSafeHwnd(), GWL_EXSTYLE, GetWindowLong(GetSafeHwnd(), GWL_EXSTYLE) | WS_EX_LAYERED);
MySetLayeredWindowAttributes(GetSafeHwnd(), maskColor, 10, LWA_COLORKEY);


 

posted on 2006-11-07 18:16 永遇乐 阅读(1021) 评论(1)  编辑 收藏 引用 所属分类: Windows MFC

评论

# re: 使窗口透明http://www.cppblog.com/Modules/CaptchaImage/JpegImage.aspx 2014-02-12 14:25 http://www.cppblog.com/Modules/CaptchaImage/JpegIm

iojltyity  回复  更多评论   


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


<2024年3月>
252627282912
3456789
10111213141516
17181920212223
24252627282930
31123456

导航

统计

常用链接

留言簿(6)

随笔分类

推荐Blog

友情链接

搜索

最新评论

阅读排行榜