Archived

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

GameDev135

Re: SelectObject function

Recommended Posts

I bought the book Tricks of the Windows Game Programming Gurus recently. I am up to the chapter regarding pens and brushes. It says that I can create a new pen by doing this: HPEN blue_pen = CreatePen(PS_SOLID, 1, RGB(255,0,0)); That works. However, the next thing that it says to do is store the old pen when I select the blue pen. HPEN old_pen = SelectObject(hdc, blue_pen); However, according to my compiler (visual studio 6.0), SelectObject() is a void function and thus cant return any value. Is the book wrong or am I doing something wrong? By the way, the blue pen is selected correctly if I simply do: SelectObject(hdc,blue_pen); Thanks. Daniel

Share this post


Link to post
Share on other sites
SelectObject() returns a void pointer , not void. The correct statement is:

HPEN old_pen = (HPEN)SelectObject( hdc, blue_pen );

You typecast the returned value/object from SelectObject to the appropriate type. This allows the same function to be used for a variety of Window handles without overloading (HFONT, HBRUSH, etc).

Tricks is full of bugs.

Share this post


Link to post
Share on other sites