Common and private DC

来源:互联网 发布:mac获取文件夹权限 编辑:程序博客网 时间:2024/05/14 09:09
Common and private DC

The two primary types of display device contexts are common and private.
(The third supported type, class, is obsolete.) When retrieving the DC handle,
the DC will be private if the window class was registered with the CS_OWNDC class style,
otherwise it will be common.

A common DC handle is retrieved when GetDC (or BeginPaint) is called. Every time it’s retrieved,
it references a new DC initialized with a default set of attributes.
Thus to keep memory usage low, the common DC should be released with ReleaseDC (or EndPaint).
The common DC is generally used as a temporary DC,
acquired and released by each message handler needing a DC.
A private DC is created when a window is created. Its handle can be retrieved with the GetDC (or BeginPaint) function,
and it’s not necessary to call ReleaseDC. Unlike the common DC,
it is not reinitialized on retrieval.
As a result, you avoid the need to reset all your drawing tools and modes with every message requiring graphics.