BitBlt 问题 GDI
我在这个程序中使用 BitBlt 时遇到问题。您调整窗口的大小,椭圆也会随之调整。当然,使用普通的 hdc 方法,会出现断断续续和闪烁的情况。我尝试了 BitBlt 方法,但这也不起作用(可能是因为我做错了)。 有人可以解决我做错的事情吗?谢谢
bool sizing; //global
case WM_PAINT:
{
RECT rect;
GetClientRect(hwnd, &rect);
hdc = BeginPaint(hwnd, &ps);
mem = CreateCompatibleDC(hdc);
SelectObject(mem, GetStockObject(HOLLOW_BRUSH));
if(sizing)
{
Ellipse(mem,rect.left, rect.top, rect.right, rect.bottom);
}
BitBlt(hdc, rect.left, rect.top, rect.left - rect.right, rect.top -rect.bottom , mem, rect.left, rect.top, SRCCOPY);
DeleteDC(mem);
EndPaint(hwnd, &ps);
break;
}
case WM_SIZE:
sizing = true;
break;
I am having trouble with using BitBlt in this program. You resize the window and the ellipse resizes with it. Of course, with the normal hdc method, It is choppy and flickery. I tried the BitBlt method, but that doesn't work either (probably because im doing it wrong).
Can someone fix my what Im donig wrong? thanx
bool sizing; //global
case WM_PAINT:
{
RECT rect;
GetClientRect(hwnd, &rect);
hdc = BeginPaint(hwnd, &ps);
mem = CreateCompatibleDC(hdc);
SelectObject(mem, GetStockObject(HOLLOW_BRUSH));
if(sizing)
{
Ellipse(mem,rect.left, rect.top, rect.right, rect.bottom);
}
BitBlt(hdc, rect.left, rect.top, rect.left - rect.right, rect.top -rect.bottom , mem, rect.left, rect.top, SRCCOPY);
DeleteDC(mem);
EndPaint(hwnd, &ps);
break;
}
case WM_SIZE:
sizing = true;
break;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来您正在尝试绘制基于内存的位图,然后将其位传输到屏幕,以避免闪烁?
这里的第一个问题是处理闪烁:首先您需要重写 WM_ERASEBKGND,正如 Hans 指出的那样 - 否则 Windows 将使用任何窗口画笔(来自 RegisterClass)擦除背景,而擦除是闪烁的常见原因。
这里的下一个问题是您使用的是“空”DC:CreateCompatibleDC 为您提供了一个 DC - 这只是一个绘图上下文 - 但该上下文包含一个 1 像素 x 1 像素位图。要在屏幕外绘制,您需要一个 DC 和一个位图。请花些时间阅读CreateCompatible 的 MSDN 页面 - 它指出了这一点确切的问题。
如果您对此不熟悉,请将位图视为您在其上绘制的实际画布 - DC 只是执行该绘制的支撑结构。正如您的代码所示,您已经设置了画架和画笔 - 但您没有在任何东西上绘画。
这里通常的方法是:
It looks like you're trying to draw to a memory-based bitmap, and then bitblt that to the screen, to avoid flicker?
First issue here is dealing with flicker: first you need to override WM_ERASEBKGND as Hans points out - otherwise Windows will erase the background with whatever the window brush is (from RegisterClass), and that erasing is the usual cause of flicker.
The next problem here is that you're using an 'empty' DC: CreateCompatibleDC gives you a DC - which is just a drawing context - but the context contains a 1 pixel by 1 pixel bitmap. To draw offscreen, you need a DC and a bitmap. Do take time to read the MSDN page for CreateCompatible - it calls out this exact issue.
If you're new to this, think of a bitmap as the actual canvas that you draw on - the DC is just the support structure to do that drawing. As your code stands, you've got the easel and paint brushes set up - but you're not painting on anything.
The usual approach here is: