VC++: How would you convert a handle into a pointer?
How would you convert a handle into a pointer?
Very often we get a handle of an object and we need to convert it to a pointer to that object. For this FromHandle( ) function can be used. Following code snippets show how to get a pointer to different classes from a handle.
HBRUSH hb = ( HBRUSH ) GetStockObject ( BLACK_BRUSH ) ; CBrush *b = CBrush::FromHandle ( hb ) ; HDC hdc = ::GetDC ( NULL ) ; CDC* pDC = CDC::FromHandle ( hdc ) ; CWnd *pWnd = ( CWnd * ) ::FromHandle ( m_hWnd ) ;




Comments
Log in or create a user account to comment.