简体   繁体   English

GDI双缓冲黑色闪烁

[英]GDI Double Buffer Black Flicker

I am using this BitBlt wrapper: 我正在使用这个BitBlt包装器:

http://www.codeproject.com/Articles/21426/Double-Buffering-in-a-Win-API-Program http://www.codeproject.com/Articles/21426/Double-Buffering-in-a-Win-API-Program

I initialize it in main(): 我在main()中初始化它:

biop = new Bitmap_Operations();
biop->Initialize_Buffers(m_hDC, m_hWND, 1);
biop->Create_Buffer(0);

Helper Functions: 助手功能:

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);
}

I spawn a thread to render data: 我产生一个线程来呈​​现数据:

// Inside a thread
while (1)
{
    CreateBuffer();
    for (int i = 0; i < 1028; i++)
    {
        //

        DrawBox()

        //
    }
    Render();
    ClearBuffer();
}

I am using FindWindow() to render on top of another application. 我正在使用FindWindow()在另一个应用程序之上进行渲染。 Everything works fine, the boxes get rendered, ect, but there is a crazy full-screen flicker that seems to have a black background. 一切正常,盒子被渲染,等等,但有一个疯狂的全屏闪烁似乎有一个黑色的背景。 My guess its when I draw from memory to the application? 当我从内存中抽取应用程序时,我的猜测是什么?

I am using double buffering to avoid a flicker, but it seems like it made it worse. 我使用双缓冲来避免闪烁,但似乎它使它变得更糟。 Any ideas? 有任何想法吗?

Thanks. 谢谢。

如果你需要在现有窗口之上绘制透明的东西,我会使用UpdateLayeredWindow API。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM