This topic is now archived and is closed to further replies.


A problem using the SelectObject function

Recommended Posts

I keep getting this damn error in Visual C++ when I try to use the Select Object function. Here is the error:
error C2440: '=' : cannot convert from 'void *' to 'struct HBRUSH__ *'
        Conversion from 'void*' to pointer to non-'void' requires an explicit cast
Here is the code. The first SelectObject function is the line with the error:
case WM_PAINT:
				HBRUSH hOldBrush;

				// Start Painting

				BeginPaint(hWnd, &ps);

				// Select and use the red brush

				hOldBrush = SelectObject(ps.hdc, hRedBrush);

				// Draw a rectangle filled with the currently selected brush

				Rectangle(ps.hdc, 100, 100, 150, 150);

				// Deselect the brush

				SelectObject(ps.hdc, hOldBrush);

				// End painting

				EndPaint(hWnd, &ps);
Anyone got any ideas? [edited by - Steve-B on August 11, 2003 6:10:56 PM]

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
it''s probably not the parm but the return value assignment that''s causing the error. change hOldBrush to a HGDIOBJ and the error should go away.

Share this post

Link to post
Share on other sites