GDI双缓冲区黑色闪烁
GDI Double Buffer Black Flicker
我正在使用这个BitBlt包装器:
http://www.codeproject.com/Articles/21426/Double-Buffering-in-a-Win-API-Program
我在main()中初始化它:
biop = new Bitmap_Operations();
biop->Initialize_Buffers(m_hDC, m_hWND, 1);
biop->Create_Buffer(0);
助手功能:
void CreateBuffer()
{
biop->Create_Buffer(0);
}
void Render()
{
biop->Copy_to_Screen(0);
}
void ClearBuffer()
{
biop->Free_Buffer(0);
}
void DrawBox(int x, int y, int r, int g, int b, int size, int thickness)
{
// Brush style to hollow
m_LogBrush.lbStyle = BS_NULL;
// Create a logical brush and select into the context
m_hBrush = CreateBrushIndirect(&m_LogBrush);
HBRUSH hbrOldBrush = (HBRUSH)SelectObject(biop->Get_DC_Buffer(0), m_hBrush);
// Create a logical pen and select into the context
m_hPen = CreatePen(PS_SOLID, thickness, RGB(r, g, b));
HPEN hpOldPen = (HPEN)SelectObject(biop->Get_DC_Buffer(0), m_hPen);
// Draw the rectangle
Rectangle(biop->Get_DC_Buffer(0), (x - size / 2), (y - size / 2), (x + size / 2), (y + size / 2));
// Remove the object
SelectObject(biop->Get_DC_Buffer(0), hbrOldBrush); // first you must restore DC to original state
SelectObject(biop->Get_DC_Buffer(0), hpOldPen); // same here
DeleteObject(m_hBrush);
DeleteObject(m_hPen);
}
我生成一个线程来渲染数据:
// Inside a thread
while (1)
{
CreateBuffer();
for (int i = 0; i < 1028; i++)
{
//
DrawBox()
//
}
Render();
ClearBuffer();
}
我正在使用FindWindow()在另一个应用程序上进行渲染。一切都很好,方框被渲染,等等,但有一个疯狂的全屏闪烁,似乎有一个黑色的背景。我猜是什么时候从内存中提取到应用程序?
我使用双重缓冲来避免闪烁,但它似乎让情况变得更糟。有什么想法吗?
谢谢。
如果需要在现有窗口上绘制透明的东西,我会使用UpdateLayeredWindow API。
相关文章:
- 处理闪烁窗口事件
- 如何避免LED在循环状态变化中闪烁?
- 除非重新绘制大小,否则SDL_Texture在调整大小后呈现黑色
- 为什么我会得到黑色纹理?
- ExtTextOut 文本的持续闪烁,在一段时间后,文本将恢复为默认字体
- 具有 GPU 时间表的卤化物产生黑色图像
- OpenGL只是渲染一个黑色的方块
- 为什么在使用VK_PRESENT_MODE_FIFO_KHR呈现模式调整交换链图像大小时出现白色闪烁
- 如何在不闪烁的情况下运行ESP32的单元测试
- 清除控制台时C++闪烁
- 使用 Cmake 闪烁浏览器引擎示例?
- 黑色纹理,如果图片大小在第二个 OpenGL 线程中> 1 * 1
- 为什么当我输入大量数字时,我的计算器程序开始闪烁和滚动
- 在鼠标按下时移动 SDL2 窗口的功能闪烁窗口并且移动速度不够快
- 将未签名的字符转换为红黑色树的签名字符
- 对话框窗体快速闪烁,但之后未正确绘制
- CImage::D raw() 画了一幅黑色的图画
- 纹理显示为黑色
- openCV中的Absdiff可以编译,但显示黑色图像
- GDI双缓冲区黑色闪烁