Layered Window(分层窗体,透明窗体)
来源:互联网 发布:微博淘宝优惠券骗局 编辑:程序博客网 时间:2024/04/27 19:43
转自:http://www.360doc.com/content/10/0913/09/2631212_53246332.shtml
效果1.窗体整体透明,支持子控件,支持OnPaint()
//为窗体添加WS_EX_LAYERED属性,该属性使窗体支持透明
ModifyStyleEx(0, WS_EX_LAYERED);
效果1.1 窗体整体透明,子控件也透明
//设置Alpha值为150
BYTE byteAlpha=150;
SetLayeredWindowAttributes(0,byteAlpha,LWA_ALPHA);
效果1.2 窗体整体透明,子控件不透明
//在OnCtlColor中将窗体背景刷为某种单色,比如RGB(255,0,0)
//在OnPaint中当然也可以
//在OnPaint中当然也可以
if(nCtlColor=IDD)
return m_brush; //m_brush.CreateSolidBrush(RGB(255,0,255));
//设置窗体中所有单色区域都透明
SetLayeredWindowAttributes(RGB(255,0,255),0,LWA_COLORKEY);
效果2.窗体部分透明,但该窗体不支持子控件,不支持OnPaint()
USES_CONVERSION;
Image* _pImage=
Image::FromFile(A2W("F:\\Desktop\\TestTransparentWnd\\test.png"));
//透明度由PNG图片的Alpha通道决定
//如果加上WS_EX_TRANSPARENT属性,则鼠标会穿透此窗体
ModifyStyleEx(0, WS_EX_LAYERED/*|WS_EX_TRANSPARENT*/);
CDC *pDCDst=this->GetDC();
CDC dcSrc;
dcSrc.CreateCompatibleDC(pDCDst);
CBitmap bmp;
bmp.CreateCompatibleBitmap(pDCDst,300,300);
dcSrc.SelectObject(&bmp);
//用GDI+显示PNG图片
Graphics _Graphics(dcSrc.m_hDC);
_Graphics.DrawImage(_pImage,0,0,300,300);
BLENDFUNCTION _Blend;
_Blend.BlendOp=0;
_Blend.BlendFlags=0;
_Blend.AlphaFormat=1;
_Blend.SourceConstantAlpha=255;
//此时,鼠标会穿透窗体中Alpha值为0的区域
UpdateLayeredWindow(pDCDst,&CPoint(0,0),&CSize(300,300),
&dcSrc,&CPoint(0,0),
0,&_Blend,ULW_ALPHA);
bmp.DeleteObject();
dcSrc.DeleteDC();
_Graphics.ReleaseHDC(dcSrc.m_hDC);
this->ReleaseDC(pDCDst);
3.既要窗体部分透明(鼠标能穿透窗体中Alpha值为0的区域),还要能显示控件
解决方案:
创建两个窗体,窗体A使用效果2的方法,作为背景窗体;窗体B使用效果1.2的方法,作为前景窗体,控件都放在窗体B上。在窗体A的OnMove中,同步移动窗体B。
参考:http://blog.csdn.net/srxumin/article/details/4410917
效果:
备注:
1.以上代码只需在窗体初始化的时候(如OnInitDialog)执行一次即可
2.WS_EX_LAYERED要求宏_WIN32_WINNT >= 0x0500
3.以上程序需要GDI+支持
参考资料:
http://msdn.microsoft.com/en-us/library/ms997507.aspx
http://www.codeproject.com/KB/dialog/PerfectTranlucentDlg.aspx
- Layered Window(分层窗体,透明窗体)
- Layered Window(分层窗体,透明窗体)
- Layered Window(分层窗体,透明窗体)
- Layered Window(分层窗体,透明窗体)
- Layered Window(分层窗体,透明窗体)
- Layered Window(分层窗体,透明窗体)
- Layered Window(分层窗体,透明窗体)
- Layered Window 透明窗体的实现总结
- GUI分层技术(分层窗体、Layered Window)
- Layered Windows 实现透明窗体
- 分层窗体,透明窗体(转)
- Window 透明窗体的实现总结
- 窗体透明
- 透明窗体
- 透明窗体
- 透明窗体
- 透明窗体
- 透明窗体子窗体显示
- 测试系统可供malloc()使用的内存空间大小
- __attribute__ ((format (printf, 2, 3)));
- hdu 2067小兔的棋盘
- Android_播放器_利用Service通过MediaPlayer播放歌曲并完成歌词同步绘制
- deinterlace 隔行 progressive 逐行 3:2pulldown
- Layered Window(分层窗体,透明窗体)
- java对类私有变量的暴力反射
- 安装ftp - linux
- 我的代码MAIN11.20
- Java toString()在多继承关系中的应用
- python 专题十四 字典
- python 成长笔记 序章
- Hadoop MapReduce 计数器
- 归并排序求逆序对