Jump to content
  • Advertisement

Archived

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

GameDev135

Re: SelectObject function

This topic is 6174 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
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.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!