我几乎从没有显式调用过这个方法,也从没遇到过问题。
想问一下CWnd::ReleaseDC()这个方法究竟什么时候需要显式调用?MSDN上的关于GetDC()的说明:
Unless the device context belongs to a window class, the ReleaseDC
member function must be called to release the context after painting.A device context belonging to the CWnd class is returned by the GetDC
member function if CS_CLASSDC, CS_OWNDC, or CS_PARENTDC was specified
as a style in the WNDCLASS structure when the class was registered.个人理解是否缺省情况下,GetDC()得到的CDC*就是“归属于”CWnd类的?
想问一下CWnd::ReleaseDC()这个方法究竟什么时候需要显式调用?MSDN上的关于GetDC()的说明:
Unless the device context belongs to a window class, the ReleaseDC
member function must be called to release the context after painting.A device context belonging to the CWnd class is returned by the GetDC
member function if CS_CLASSDC, CS_OWNDC, or CS_PARENTDC was specified
as a style in the WNDCLASS structure when the class was registered.个人理解是否缺省情况下,GetDC()得到的CDC*就是“归属于”CWnd类的?
缺省情况下,GetDC()得到的CDC*就是“归属于”CWnd类的。也就是说,ReleaseDC()只有对于自注册的窗体类,才可能是需要的。
{
HDC hDC; for( int iDC = 0; iDC < CIMAGE_DC_CACHE_SIZE; iDC++ )
{
hDC = static_cast< HDC >( InterlockedExchangePointer( reinterpret_cast< void** >(&m_ahDCs[iDC]), NULL ) );
if( hDC != NULL )
{
return( hDC );
}
} hDC = ::CreateCompatibleDC( NULL ); return( hDC );
}inline void CImage::CDCCache::ReleaseDC( HDC hDC ) throw()
{
for( int iDC = 0; iDC < CIMAGE_DC_CACHE_SIZE; iDC++ )
{
HDC hOldDC; hOldDC = static_cast< HDC >( InterlockedExchangePointer( reinterpret_cast< void** >(&m_ahDCs[iDC]), hDC ) );
if( hOldDC == NULL )
{
return;
}
else
{
hDC = hOldDC;
}
}
if( hDC != NULL )
{
::DeleteDC( hDC );
}
}inline HDC CImage::GetDC() const throw()
{
ATLASSUME( m_hBitmap != NULL ); m_nDCRefCount++;
if( m_hDC == NULL )
{
m_hDC = s_cache.GetDC();
m_hOldBitmap = HBITMAP( ::SelectObject( m_hDC, m_hBitmap ) );
} return( m_hDC );
}inline void CImage::ReleaseDC() const throw()
{
HBITMAP hBitmap; ATLASSUME( m_hDC != NULL ); m_nDCRefCount--;
if( m_nDCRefCount == 0 )
{
hBitmap = HBITMAP( ::SelectObject( m_hDC, m_hOldBitmap ) );
ATLASSERT( hBitmap == m_hBitmap );
s_cache.ReleaseDC( m_hDC );
m_hDC = NULL;
}
}
不需要的,而且OnPaint()中应该用CPaintDC的