[转]MFC制作不规则窗体
2015-11-04 00:10
204 查看
1.制作png图片。注意边界,多试几次会明白我的意思的
2.m_image为CImage类,在OnInitDialog()里加上:
ModifyStyleEx(0,WS_EX_LAYERED);
m_image.Load(_T("res\\test1.png"));
DrawUI();
DrawUI()实现如下:
void CdirectUITest2Dlg::DrawUI()
{
HDC hDC=::GetDC(m_hWnd);
HDC hMemDC=::CreateCompatibleDC(hDC);
BITMAPINFO bitmapinfo;
bitmapinfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bitmapinfo.bmiHeader.biBitCount = 32;
bitmapinfo.bmiHeader.biHeight =500;
bitmapinfo.bmiHeader.biWidth = 500;
bitmapinfo.bmiHeader.biPlanes = 1;
bitmapinfo.bmiHeader.biCompression=BI_RGB;
bitmapinfo.bmiHeader.biXPelsPerMeter=0;
bitmapinfo.bmiHeader.biYPelsPerMeter=0;
bitmapinfo.bmiHeader.biClrUsed=0;
bitmapinfo.bmiHeader.biClrImportant=0;
bitmapinfo.bmiHeader.biSizeImage = bitmapinfo.bmiHeader.biWidth * bitmapinfo.bmiHeader.biHeight * bitmapinfo.bmiHeader.biBitCount / 8;
HBITMAP hBitmap=::CreateDIBSection (hMemDC,&bitmapinfo, 0,NULL, 0, 0);
HBITMAP hOldBitmap = (HBITMAP)::SelectObject (hMemDC,hBitmap);
//画出各个界面元素----------------------
m_image.Draw( hMemDC,0,0 );
//设置透明窗口-------------------------------------------------
CPoint DestPt(0,0);
CSize psize(500,500);
BLENDFUNCTION blendFunc32bpp;
blendFunc32bpp.AlphaFormat = AC_SRC_ALPHA;
blendFunc32bpp.BlendFlags = 0;
blendFunc32bpp.BlendOp = AC_SRC_OVER;
blendFunc32bpp.SourceConstantAlpha = 255;
::UpdateLayeredWindow(m_hWnd,hDC,NULL,&psize,hMemDC,&DestPt,0,&blendFunc32bpp,ULW_ALPHA);
//释放资源-------------------------------------------------
::SelectObject (hMemDC,hOldBitmap);
::DeleteObject(hBitmap);
::DeleteDC(hMemDC);
::ReleaseDC(m_hWnd,hDC);
}
3.加上鼠标拖动
void CdirectUITest2Dlg::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
ReleaseCapture ();
SendMessage (WM_NCLBUTTONDOWN, HTCAPTION, 0);
CDialogEx::OnLButtonDown(nFlags, point);
}
2.m_image为CImage类,在OnInitDialog()里加上:
ModifyStyleEx(0,WS_EX_LAYERED);
m_image.Load(_T("res\\test1.png"));
DrawUI();
DrawUI()实现如下:
void CdirectUITest2Dlg::DrawUI()
{
HDC hDC=::GetDC(m_hWnd);
HDC hMemDC=::CreateCompatibleDC(hDC);
BITMAPINFO bitmapinfo;
bitmapinfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bitmapinfo.bmiHeader.biBitCount = 32;
bitmapinfo.bmiHeader.biHeight =500;
bitmapinfo.bmiHeader.biWidth = 500;
bitmapinfo.bmiHeader.biPlanes = 1;
bitmapinfo.bmiHeader.biCompression=BI_RGB;
bitmapinfo.bmiHeader.biXPelsPerMeter=0;
bitmapinfo.bmiHeader.biYPelsPerMeter=0;
bitmapinfo.bmiHeader.biClrUsed=0;
bitmapinfo.bmiHeader.biClrImportant=0;
bitmapinfo.bmiHeader.biSizeImage = bitmapinfo.bmiHeader.biWidth * bitmapinfo.bmiHeader.biHeight * bitmapinfo.bmiHeader.biBitCount / 8;
HBITMAP hBitmap=::CreateDIBSection (hMemDC,&bitmapinfo, 0,NULL, 0, 0);
HBITMAP hOldBitmap = (HBITMAP)::SelectObject (hMemDC,hBitmap);
//画出各个界面元素----------------------
m_image.Draw( hMemDC,0,0 );
//设置透明窗口-------------------------------------------------
CPoint DestPt(0,0);
CSize psize(500,500);
BLENDFUNCTION blendFunc32bpp;
blendFunc32bpp.AlphaFormat = AC_SRC_ALPHA;
blendFunc32bpp.BlendFlags = 0;
blendFunc32bpp.BlendOp = AC_SRC_OVER;
blendFunc32bpp.SourceConstantAlpha = 255;
::UpdateLayeredWindow(m_hWnd,hDC,NULL,&psize,hMemDC,&DestPt,0,&blendFunc32bpp,ULW_ALPHA);
//释放资源-------------------------------------------------
::SelectObject (hMemDC,hOldBitmap);
::DeleteObject(hBitmap);
::DeleteDC(hMemDC);
::ReleaseDC(m_hWnd,hDC);
}
3.加上鼠标拖动
void CdirectUITest2Dlg::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
ReleaseCapture ();
SendMessage (WM_NCLBUTTONDOWN, HTCAPTION, 0);
CDialogEx::OnLButtonDown(nFlags, point);
}
相关文章推荐
- ListSet_有序表搜索
- 如何安全的存储用户的密码
- hadoop 之 PathFilter -- 输入文件过滤器
- 项目冲刺--第三天
- 六,游戏主界面
- Android开发之ListView添加多种布局效果演示
- Lucene之——获取索引关键字给Jquery自动填充框架使用
- listView中Item控件抢占焦点
- Python 启动 Scrapy爬虫
- 个人微信公众号VI升级心路
- 用python建立最简单的web服务器
- 用户登录
- 机器学习-多变量的线性回归模型与实现笔记
- 小作坊的安全管家之软件管理
- 图像滤镜艺术---ZPhotoEngine超级算法库
- iOS学习之iOS沙盒(sandbox)机制和文件操作(一)
- varnish学习笔记
- 《30天自制操作系统》学习笔记
- linux 下MySQL主从复制
- 为什么费尽心思讲产品卖点,用户仍然不相信你?