会员
周边
众包
新闻
博问
闪存
赞助商
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
1CM
博客园
首页
新随笔
联系
订阅
管理
利用UpdateLayeredWindow函数制作透明窗口时BMP的Alpha通道的问题
void CDigitalClock::Update() { // Create the alpha blending bitmap BITMAPINFO bmi; // bitmap header ZeroMemory(&bmi, sizeof(BITMAPINFO)); bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); bmi.bmiHeader.biWidth = m_Width; bmi.bmiHeader.biHeight = m_Height; bmi.bmiHeader.biPlanes = 1; bmi.bmiHeader.biBitCount = 32; // four 8-bit components bmi.bmiHeader.biCompression = BI_RGB; bmi.bmiHeader.biSizeImage = m_Width * m_Height * 4; BYTE *pvBits; // pointer to DIB section HBITMAP hbitmap = CreateDIBSection(NULL, &bmi, DIB_RGB_COLORS, (void **)&pvBits, NULL, 0); ZeroMemory(pvBits, bmi.bmiHeader.biSizeImage); HDC hMemDC = CreateCompatibleDC(GetDC(m_hWnd)); HBITMAP hOriBmp = (HBITMAP)SelectObject(hMemDC, hbitmap); HFONT *oldFont=NULL; static char str_time[10]={""}; CTime t=CTime::GetCurrentTime(); sprintf(str_time,"%02d:%02d.%02d", t.GetHour(),t.GetMinute(),t.GetSecond()); CRect rt; GetClientRect(m_hWnd, &rt); oldFont = (HFONT*)SelectObject(hMemDC,g_this->GetFont()); SetBkColor(hMemDC,RGB(0,0,0)); SetBkMode(hMemDC,TRANSPARENT); GetClientRect(m_hWnd, &rt); FillRect(hMemDC,&rt,CBrush(RGB(128,128,128))); SetTextColor(hMemDC,RGB(255,255,255)); DrawText(hMemDC, str_time,strlen(str_time), &rt, DT_CENTER|DT_VCENTER|DT_SINGLELINE); GetWindowRect(m_hWnd,rt); POINT ptDst = {rt.left,rt.top}; POINT ptSrc = {0, 0}; SIZE WndSize = {m_Width, m_Height}; //ULW_COLORKEY 1 ULW_ALPHA 2 ULW_OPAQUE 4 //AC_SRC_OVER 0 AC_SRC_ALPHA 1 BLENDFUNCTION blendPixelFunction={AC_SRC_OVER, 0, m_iSourceConstantAlpha,AC_SRC_ALPHA }; //在这里设置BMP的Alpha值 //内存中的数据格式为 RR GG BB AL for(int m=3;m<m_Width * m_Height * 4;m+=4) *(pvBits+m)=(BYTE)m_iImageAlpha; HDC hdcScreen=::GetDC (m_hWnd); BOOL bRet =_UpdateLayeredWindow(m_hWnd, hdcScreen, &ptDst, &WndSize, hMemDC, &ptSrc, RGB(0,0,0), &blendPixelFunction, 2); //_ASSERT(bRet); // something was wrong.... // Delete used resources SelectObject(hMemDC,oldFont); SelectObject(hMemDC, hOriBmp); DeleteObject(hbitmap); DeleteDC(hMemDC); }
下载源码
posted @
2013-03-10 14:36
1CM
阅读(
520
) 评论(
0
)
编辑
收藏
举报
会员力量,点亮园子希望
刷新页面
返回顶部
公告