I'm using MFC...
When I create a new brush, I know I need to restore the old bush using SelectObject:
CBrush brushFill;
brushFill.CreateSolidBrush(colorFill);
CBrush *oldBrush = pDC->SelectObject(&brushFill);
// Draw something here.
pDC->SelectObject(oldBrush);
However, if I get the brush using GetStockObject(), do I need to to restore it, too?
CBrush *oldBrush = (CBrush *)pDC->SelectObject(GetStockObject(HOLLOW_BRUSH));
// Draw something here.
pDC->SelectObject(oldBrush);
I ask, because that code occasionally crashes. I'm unsure if that's due to me not supposed to save/restore stock items, or my typecast to a CBrush*. If the latter, I'm thinking I should save/restore an HGDIOBJ handle:
HGDIOBJ oldBrush = pDC->SelectObject(GetStockObject(HOLLOW_BRUSH));
// Draw something here.
pDC->SelectObject(oldBrush);
If the former, I wouldn't save/restore the previous object.