将双缓冲位图与 AlphaBlend 一起使用时出现的问题
The problem when using Double buffering Bitmap with AlphaBlend
我的文本在更改时重叠。
但是现在是时候文本了,所以总是在变化
我已经试过了
TranslateBlt(memhdc, TextBoxRect.left, TextBoxRect.top, TextBoxRect.right, TextBoxRect.bottom,
hdc, TextBoxRect.right, TextBoxRect.bottom, RGB(0,0,0((;
案例WM_ERASEBKGND:返回真;
InvalidateRect(NULL, &TextBoxRect, TRUE(;
这是我的代码。
HDC hdc = GetDC(NULL);
HDC memhdc;
HBITMAP bgbitmap, oldbitmap;
stringstream stream;
int cur = delay / 10;
stream << "Ms : " << msec;
wchar_t str[120];
mbstowcs_s(NULL, str, 120, stream.str().c_str(), 120);
memhdc = CreateCompatibleDC(hdc);
bgbitmap = CreateCompatibleBitmap(hdc, TextBoxRect.right, TextBoxRect.bottom);
oldbitmap = (HBITMAP) SelectObject(memhdc, bgbitmap);
BLENDFUNCTION bf;
bf.BlendOp = AC_SRC_OVER;
bf.BlendFlags = 0;
bf.SourceConstantAlpha = 255;
bf.AlphaFormat = 0;
AlphaBlend(memhdc, TextBoxRect.left, TextBoxRect.top, TextBoxRect.right, TextBoxRect.bottom, hdc, TextBoxRect.left, TextBoxRect.top, TextBoxRect.right, TextBoxRect.bottom, bf);
SetBkMode(memhdc, TRANSPARENT);
SetTextColor(memhdc, RGB(255, 0, 0));
DrawText(memhdc, str, -1, &TextBoxRect, DT_LEFT | DT_NOCLIP);
BitBlt(hdc, TextBoxRect.left, TextBoxRect.top, TextBoxRect.right, TextBoxRect.bottom, memhdc, TextBoxRect.left, TextBoxRect.top, SRCCOPY);
DeleteObject(SelectObject(memhdc,oldbitmap));
DeleteObject(bgbitmap);
DeleteDC(memhdc);
ReleaseDC(NULL, hdc);
我想你已经准备好绘制透明的数字变化了。
您可以尝试同时调用InvalidateRect
和UpdateWindow
刷新本地区域,因为系统会将窗口中的绘制操作视为低优先级操作,可以使用 UpdateWindow 立即重绘。
你也可以尝试以下代码,正如乔纳森·波特所说
就像:
AlphaBlend(memhdc, TextBoxRect.left, TextBoxRect.top, TextBoxRect.right, TextBoxRect.bottom, hdc, TextBoxRect.left, TextBoxRect.top, TextBoxRect.right, TextBoxRect.bottom, bf);
SetBkMode(hdc, TRANSPARENT);
SetTextColor(hdc, RGB(255, 0, 0));
BitBlt(hdc, TextBoxRect.left, TextBoxRect.top, TextBoxRect.right, TextBoxRect.bottom, hdc, TextBoxRect.left, TextBoxRect.top, SRCCOPY);
DrawText(hdc, str, -1, &TextBoxRect, DT_LEFT | DT_NOCLIP);
相关文章:
- 如何将GTest与CMake一起使用?遵循谷歌指南时的链接问题
- 在浮点精度成为一个问题之前,可以将多少个浮点值加在一起
- 将cpp_redis pub/sub与条件变量一起使用时出现问题
- 在本地安装OpenMPI的问题与CUDA一起使用
- 与自定义命名空间一起使用时实现 std::error_category、名称解析问题
- 与lambda一起使用虚拟继承在初始化列表中捕获此问题的GCC错误
- 将 cplex 与 netbeans c++ 一起使用,链接器问题
- 将双缓冲位图与 AlphaBlend 一起使用时出现的问题
- 有关将智能指针与 Winsock 的 addrinfo 结构一起使用的问题
- QT TreeView问题与排序模型一起使用
- 将模板气泡排序与结构数组一起使用时出现问题
- 将 boost/thread headers 与 clang++ (Windows) 一起使用时出现问题
- 将 Botan 与 Qt 一起使用时遇到问题
- 与私人成员一起上课.这个代码出了什么问题
- 将指针与动态数组一起使用时出现问题
- 将问题与多个文件链接在一起
- Clang:将绑定或mem_fn与字符串::c_str和转换一起使用时出现问题
- 将get_value与 Boost 的属性树一起使用时遇到问题
- 将字符串与 sprintf() 函数一起使用时出现问题
- 将矢量与函数一起使用,指针问题