Skip to main content
GameDev.net gamedev.net
🔒 Locked

DeselectObject???

Started by Fwar Mar 26, 2000 at 9:17 PM 0 replies 500+ views
Original Post
Fwar
Fwar
How do you go about Unselecting an object??? is there an easy function in Windows API SDK(C++)?
null_pointer
null_pointer
I guess you mean in Windows GDI? You can''t deselect an object directly, but you can save the old one and restore it when you''re done. Here''s how:



// save old objects
HBITMAP hOldBitmap = SelectObject(hDC, hMyBitmap);
HPEN hOldPen = SelectObject(hDC, hMyPen);

// do some drawing...

// restore old objects
SelectObject(hDC, hOldBitmap);
SelectObject(hDC, hOldPen);



Just make sure you save the old object of each type -- there''s no need to store more than one of each type for each DC, though:



// select in several bitmaps
HBITMAP hOldBitmap1 = SelectObject(hDC, hMyBitmap1);
HBITMAP hOldBitmap2 = SelectObject(hDC, hMyBitmap2); // not needed, as hOldBitmap2 now equals hMyBitmap1



If you''re using MFC, the code would look more like this:


CBitmap* pOldBitmap = pDC->SelectObject(pMyBitmap);


Good Luck!


- null_pointer

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.