Archived

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

What's with GDI?

This topic is 5673 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

Whenever i see examples of GDI i see stuff like this: HBRUSH red_brush = CreateSolidBrush(RGB(255,0,0)); HBRUSH old_brush = SelectObject(hdc,red_brush); //what is with this old_brush? /* * do stuff with brush */ // now here is the part i don''t get // restore old brush // ?????????? SelectObject(hdc,old_brush); //why????? this seems pointless DeleteObject(red_brush); // this makes sense So basically I am wondering what the point is of the whole old_brush thing. Why do you need and old brush? This has confused me for weeks. ------------------------------ BASIC programmers don''t die, they just GOSUB and don''t return.

Share this post


Link to post
Share on other sites
In case you still need the old brush, GDI provides a handle to it for you, whenever you give it a new brush to play with. That way, when you''re done with your new brush, you can use the old one again.

Makes a lot of sense to me. If you don''t want the old brush, you can always call DeleteObject() on it.


Chris ''coldacid'' Charabaruk <ccharabaruk@meldstar.com> <http://www.meldstar.com/~ccharabaruk/>
Meldstar Studios <http://www.meldstar.com/> - Creation, cubed.

This message double ROT-13 encrypted for additional security.

Share this post


Link to post
Share on other sites
DeleteObject can only delete objects that are not selected in any device context. Therefore, you need the second SelectObject call to deselect the object you created. But since you must select something back, you save the object that was in the DC before you got it.

Share this post


Link to post
Share on other sites
Oh I see... I didn''t realize SelectObject returns the oject that was previously selected. It almost makes sense now . I should stick to DirectX and COM, it makes much more sense . haha j/k. Thanks for your help.

------------------------------
BASIC programmers don''t die, they just GOSUB and don''t return.

Share this post


Link to post
Share on other sites