我试图了解如何正确释放 GDI 资源,在阅读了许多 GDI 教程后,我认为这是如何完成的:
假设我已经创建了一个内存 DC,并创建并选择了许多 GDI 对象(HPEN
、HBRUSH
、HBITMAP
等)进去。现在要释放 GDI 资源,我将执行以下操作:
- 将所有旧的 GDI 对象选择到内存 DC 中(因此 选择所有新创建的 GDI 对象)。
- 删除新创建的 GDI 对象。
- 删除内存 DC。
请注意,第二步和第三步可以按相反的顺序执行。即内存DC被删除为GDI对象。
如果我使用的是普通 DC(我使用 GetDC() 或 BeginPaint() 获得的),我会用释放 DC 来代替删除 DC .
我做对了吗,还是我遗漏了什么?
最佳答案
- Select all of the old GDI object into the memory DC (and hence selecting out all of the newly created GDI objects).
- Delete the newly created GDI objects.
- Delete the memory DC.
Note that the second and third steps can be performed in reverse order. That is the memory DC is deleted for the GDI objects are.
Did I get this right?
是的,你做到了。
And if I am working with a normal DC (that I got using
GetDC()
orBeginPaint()
), I would replace deleting the DC with just releasing it.
嗯,GetDC
将与 ReleaseDC
匹配,BeginPaint
将与 EndPaint
匹配。至于 GetDC
,请注意 documentation 中的以下内容:
After painting with a common DC, the ReleaseDC function must be called to release the DC. Class and private DCs do not have to be released.
关于c - 如何正确释放GDI资源?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33497466/