您的位置:首页 > 其它

What does the CS_CLASSDC & CS_OWNDC class style do?

2010-12-10 17:07 573 查看
关于这两个类型的解释可以参考这两个地方:



(1)两篇出自The Old New Thing的很有意思的文章 CS_CLASSDC

CS_OWNDC





(2)Feng Yuan的Windows Graphics
Programming Win32 GDI and DirectDraw®


第五章第二节



Class Device Context

The CS_CLASSDC flag in WNDCLASS's style field tells the window management
module to create a device context shareable by all windows of the particular
class. Such a device context is called class device context.

The actual
device context is created when the first window instance of that class is
created, and initialized once to its default values.

When GetDC, GetWindowDC, or BeginPaint is called on a window belonging to
such a class, the device context attached with the window class is returned,
with an updated display rectangle, visible region, and empty clipping region.
All other attributes in the class device context are kept the same—for example,
logical pen, text color, mapping mode, etc. After finishing drawing, ReleaseDC
or EndPaint returns the device context to the window class, without destroying
it or resetting its attributes. A class device context is destroyed only when
the last window of the class is destroyed.

If you have ever heard that ReleaseDC and EndPaint can be omitted for class
device context because they do nothing, forget about it. This kind of suggestion
should be considered harmful, because it can cause big trouble for a small gain.
For one thing, EndPaint restores the caret turned off by BeginPaint.

Class device context is useful for control windows that are drawn using the
same attribute values, because it minimizes the time required to prepare a
device context for drawing and releasing afterward. Another benefit of class
device context is its minimum memory usage.

Class device context is provided only for backward compatibility. Its
advantage is diminished by today's larger RAM and faster CPU, and by the
protected address space design of Win32 processes. Class device context is not
recommended in Win32 programming.

Private Device Context

The CS_OWNDC flag in WNDCLASS's style field tells the window management
module to create one device context for each window created using this class. So
every window will have a dedicated device context during the lifetime of the
window—that is, a private device context.

A private device context gets initialized once to its default values. Each
call to GetDC, GetWindowDC, or BeginPaint retrieves a window's private device
context, with a new display rectangle and visible region. The application can
then set device context's attribute and issue drawing commands. ReleaseDC or
EndPaint returns the device context to the window, without changing the device
context, so the next time a device context is requested, attributes like pen and
brush are still the same.

The MSDN documentation on private device context is not clear (check the
Private Display Device Contexts portion). It mentions that the application must
retrieve the handle only once, and then it goes on to say the application could
call BeginPaint to incorporate the update region.

Private device context goes to an extreme to improve performance by
sacrificing memory resource. A device context uses three types of resource: a
GDI handle, memory in the user application's address space, and memory in system
kernel address space. Private device context is useful only for windows with
complicated settings that take a long time to prepare, and for windows that need
frequent updating. It's recommended only when performance considerations are
much more important than memory and GDI handle resource usage.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐