在客户区绘画时闪烁 [英] Flickering while painting on the client area
本文介绍了在客户区绘画时闪烁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了一个简单的Win32程序,它绘制存储在链表中的矩形。在WM_PAINT消息中,程序在循环中绘制链接列表中的所有节点(矩形)。问题是该程序有点闪烁。我发现程序很烦人。我现在正在使用双缓冲,但它的结果比我预期的要少。这是我的代码:
case WM_PAINT:
// 获取窗口DC
hdc = BeginPaint(hwnd, &安培; PS);
// 为双缓冲创建一个屏幕外的DC
hdcMem = CreateCompatibleDC(hdc);
hbmMem = CreateCompatibleBitmap(hdc,win_width,win_height);
hOld = SelectObject(hdcMem,hbmMem);
// 在此处绘制到hdcMem
while ( / * 链接列表* / )
{
矩形( / * ... * / );
// ....其他代码行
}
// 将屏幕外DC转移到屏幕
BitBlt( hdc, 0 , 0 ,win_width,win_height,hdcMem, 0 , 0 ,SRCCOPY);
// 释放屏幕外的DC
SelectObject(hdcMem,hOld);
DeleteObject(hbmMem);
DeleteDC(hdcMem);
EndPaint(hwnd,& ps);
返回 0 ;
以上代码出了什么问题?有没有更好的方法来使用GDI做这样的绘画?
解决方案
看到这个:
< a href =http://stackoverflow.com/questions/2473799/gdi-double-buffering-in-c> http://stackoverflow.com/questions/2473799/gdi-double-buffering-in-c [ ^ ]
I have created a simple Win32 program which paints rectangles stored in a linked list. In the WM_PAINT message the program paints all the nodes (rectangles) in the linked list in a loop. The problem is that the program flickers a bit. I found the program is annoying to use. I am using double buffering now, but it has less results that i expected. Here''s my code :
case WM_PAINT:
// Get DC for window
hdc = BeginPaint(hwnd, &ps);
// Create an off-screen DC for double-buffering
hdcMem = CreateCompatibleDC(hdc);
hbmMem = CreateCompatibleBitmap(hdc, win_width, win_height);
hOld = SelectObject(hdcMem, hbmMem);
// Draw into hdcMem here
while(/*Linked list*/)
{
Rectangle(/*...*/);
//.... other lines of code
}
// Transfer the off-screen DC to the screen
BitBlt(hdc, 0, 0, win_width, win_height, hdcMem, 0, 0, SRCCOPY);
// Free-up the off-screen DC
SelectObject(hdcMem, hOld);
DeleteObject(hbmMem);
DeleteDC (hdcMem);
EndPaint(hwnd, &ps);
return 0;
What''s wrong with the above code ? Is there a better way to do paintings like this using GDI ?
解决方案
See this:
http://stackoverflow.com/questions/2473799/gdi-double-buffering-in-c[^]
这篇关于在客户区绘画时闪烁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文