zoukankan
html css js c++ java
利用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); }
下载源码
查看全文
相关阅读:
leetcode — spiral-matrix-ii
leetcode — spiral-matrix
leetcode — maximum-subarray
leetcode — n-queens
leetcode — powx-n
leetcode — anagrams
bzoj 2194: 快速傅立叶之二 FFT
bzoj 4503 两个串 快速傅里叶变换FFT
Codeforces 762D Maximum path 动态规划
Codeforces 762C Two strings 字符串
原文地址:https://www.cnblogs.com/nlsoft/p/2952681.html
最新文章
【Python】使用多个迭代器
【Python】迭代器
【Python】functools.wraps定义函数装饰器
【Python】回文
【LeetCode】28. Implement strStr()
【LeetCode】27. Remove Element
Base64编码的深入认识与理解
获取下拉框的值
js 手机号验证
四级联动
热门文章
jQuery的$(#id)和document.getElementById(id)的区别
js 遍历
js遍历一个元素下的所有img标签,并取得src
utf8_bin跟utf8_general_ci的区别
Host is not allowed to connect to this MySQL server解决方法
见证服务器
leetcode — unique-paths
leetcode — rotate-list
leetcode — permutation-sequence
leetcode — merge-intervals
Copyright © 2011-2022 走看看