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.
(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.
相关文章推荐
- 哈佛:孰对孰错 中英字幕 What's the right thing to do
- What does the three dots in react do?
- 调试记录:The public type <<classname>> must be defined in its own file
- What does Class.forname method do?
- What Does The HANDLECOLLISIONS Parameter Do? [ID 966207.1]
- [转]关于 "the serializable class XXX does not declare a static final seriaVersionUID..."的问题 (2012-03-1
- What does the PF function do in Primefaces
- VS 如何自动生成 aspx.designer.cs文件内容(解决"The base class includes the field ''"错误)
- What does the LayoutAwarePage Class provide
- Justice: What's the Right Thing to Do
- UVaLive 6581 && Gym 100299B What does the fox say? (模拟+STL)
- [stackoverflow翻译] “yield” 关键字有什么用?what-does-the-yield-keyword-do
- 《公正:该如何做是好?》(Justice: What's the Right Thing to Do? )【youtube上最受欢迎讲座】【哈佛大学最受新生喜爱公共课】【更新BBC里斯讲座】
- What does Class.forName(); do?
- Fixing the security exception : "class /"" + packageName + "/" does not match trust level of other classes in the same package"
- what-is-the-bios-and-what-does-it-do
- What Can I do if "The type initializer for 'Emgu.CV.CvInvoke' threw an exception"?
- Mongoose - What does the exec function do?
- About Derby "ERROR 42X51: The class '***' does not exist or is inaccessible. This can hap pen if the class is not public."
- The type or namespace name 'Windows' does not exist in the class or namespace 'System'