将一个DeviceContext的内容复制到另一个DeviceContext [英] Copy contents of one DeviceContext to another DeviceContext

查看:70
本文介绍了将一个DeviceContext的内容复制到另一个DeviceContext的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从未做过任何GDI编程,尽管在黑暗中拍摄了几张照片并搜索了文档,但我还没有找到将一个DC的内容复制到另一个DC的正确方法.

I've never done any GDI programming and despite taking several shots in the dark and searching the documentation I haven't found the correct way to do copy the contents of one DC to another DC.

我目前的代码在下面.我不明白为什么它不起作用(创建后窗口仍然保持空白).

The code I have at the moment is below. I don't understand why it's not working (the window remains just remains blank after creation).

SIZE srcSize;
// ... Get size of source DC

HDC destDC = ...;   // from GetDC(myWindow), myWindow was
                    // sized before this to properly contain source
HDC sourceDC = ...;

HBITMAP buffer = CreateCompatibleBitmap(sourceDC, srcSize.cx, srcSize.cy);
HGDIOBJ oldObj = SelectObject(destDC, buffer);
BitBlt(destDC, 0, 0, srcSize.cx, srcSize.cy, sourceDC, 0, 0, SRCCOPY);
SelectObject(destDC, oldObj);
DeleteObject(buffer);

//... ReleaseDC()s here

完成此操作的正确方法是什么?

What's the proper way this is done?

推荐答案

从一个DC复制到另一个DC的唯一必要条件是BitBlt.有效的代码如下.

The only thing necessary to copy from one DC to another is a BitBlt. Code that works is below.

SIZE srcSize;
// ... Get size of source DC

HDC destDC = ...;   // from GetDC(myWindow), myWindow was
                    // sized before this to properly contain source
HDC sourceDC = ...;

BitBlt(destDC, 0, 0, srcSize.cx, srcSize.cy, sourceDC, 0, 0, SRCCOPY);
//... ReleaseDC()s here

这篇关于将一个DeviceContext的内容复制到另一个DeviceContext的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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