CombineRgn的白色闪烁 [英] White Flicker with CombineRgn

查看:117
本文介绍了CombineRgn的白色闪烁的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎闪烁是由CombineRgn函数产生的,但我真的不知道为什么会发生这种情况,因为我从来没有使用太多的区域,我可能会遗漏一些关于此事的知识。



程序中的某些事件会触发向主区域添加小矩形,这里是处理该区域的代码:

It seems the flickering is generated by the CombineRgn function, but I really have no idea why this happens, since i've never used regions that much I'm possibly missing some knowledge on the matter.

Some events in the program triggers the addition of little rectangles to the main region, here's the code that handles that:

HRGN ActualRegion = CreateRectRgn(0, 0, 0, 0);
GetWindowRgn(hwnd, ActualRegion);
HRGN AddedRect = CreateRectRgn(//long code that creates a rectangle)
CombineRgn(ActualRegion, ActualRegion, AddedRect, RGN_OR);

SetWindowRgn(hwnd, ActualRegion, FALSE);
InvalidateRect(hwnd, NULL, FALSE);





白色闪烁仅在失效后出现,如果新区域与主要区域合并。





这是我在WM_PAINT中实现双缓冲的方式:

请注意,在创建时我将启用DWM模糊具有无效区域(与主要区域不同)的功能,这意味着用BLACK_BRUSH绘制的所有内容都将导致程序的100%不可见部分



White Flickering appears only after the invalidation if new regions where combined to the main one.


Here's how I'm implementing double buffering in WM_PAINT:
PLEASE NOTE that on creation i'm enabling the DWM blur behind function with an invalid region (different from the Main one) which means that everything painted with BLACK_BRUSH will result in a 100% "invisible" portion of the program

RECT r;	GetClientRect(hwnd, &r);

		PAINTSTRUCT ps; HDC hdc = BeginPaint(hwnd, &ps);
		HDC MemDc = CreateCompatibleDC(hdc);
		HBITMAP hBmp = CreateCompatibleBitmap(hdc, r.right, r.bottom);
		HBITMAP hOld = (HBITMAP)SelectObject(MemDc, hBmp);

		//Making sure this dc is filled with "invisible" pixels to display
		SelectObject(MemDc, GetStockObject(BLACK_BRUSH));
		Rectangle(MemDc, //arbitrary values that matches the entire screen);

		BitBlt(hdc, 0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), MemDc, 0, 0, 		SRCCOPY);

		//clean-up
		SelectObject(MemDc, hOld);
		DeleteObject(hBmp);
		DeleteDC(MemDc);
		EndPaint(hwnd, &ps);





WM_ERASEBKGND显然返回TRUE而无需进一步处理,窗口的WNDCLASSEX实例有一个默认的BLACK_BRUSH作为hbrBackground字段。

这是我可能错过的东西吗?我无法真正理解在这种情况下可能导致白色闪烁的原因



WM_ERASEBKGND obviously returns TRUE without further handling, the WNDCLASSEX instance of the window has a default BLACK_BRUSH as the hbrBackground field.
Is it something that i'm possibly missing ? I can't really understand what may be causing white flickering in this scenario

推荐答案

请参阅我对该问题的评论。要理解这个想法,请参阅,例如,

http: //snipd.net/double-buffering-with-a-back-buffer-in-vc [ ^ ],

http://www.robertelder.ca/doublebuffering [ ^ ]。



-SA
Please see my comment to the question. To understand the idea, see, for example,
http://snipd.net/double-buffering-with-a-back-buffer-in-vc[^],
http://www.robertelder.ca/doublebuffering[^].

—SA


这篇关于CombineRgn的白色闪烁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆