🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Re: SelectObject function

Started by
0 comments, last by GameDev135 22 years, 11 months ago
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
Feel free to email me at NYYanks432@hotmail.com if you have any questions
Advertisement
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.

This topic is closed to new replies.

Advertisement