Re: SelectObject function
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
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.
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
Popular Topics
Advertisement