My App is throwing a resource exception within
CPen::CPen(style,width,colorref).
The App is drawing buttons onto two touch screens. Each touch screen
has 56 buttons. I have found that reducing the amount of buttons
increases the number of page refreshes before the resource exception is
thrown. I am assuming that the error is within the button drawing
code.
Below is an example of how I am drawing within the button classes. Is
there anything inherantly wrong with the code below which maybe leading
to resource leaks?
I am considering creating the GDI objects like brushes and pens as a
member. I only actually need two pens and two brushes for the whole
app. I am assuming I would increase performance if I did this also?
Any help, even scathing critique much appreciated!
==code
void CPepButton::DrawBorder(CMonitor &monitor, const
ButtonPositionIndex &nIndex,const bool isHighlighted)const
{
CMonitorDC dc( &monitor );
CBrush* pOldBrush = NULL;
CPen* pOldPen = NULL;
CPen orangePen(PS_SOLID,LINE_THICKNESS,ORANGE);
pOldPen = dc.SelectObject(&orangePen);
if(isHighlighted)
{
CBrush brDraw(ORANGE);
pOldBrush = dc.SelectObject(&brDraw);
//Draw the bounding box
dc.Rectangle( & m_ButtonRect);
brDraw.DeleteObject();
}
else
{
CBrush brDraw(BLACK);
pOldBrush = dc.SelectObject(&brDraw);
//Draw the bounding box
dc.Rectangle( & m_ButtonRect);
brDraw.DeleteObject();
}
//reselect GDI objects
if(pOldPen!=NULL)
{
dc.SelectObject(pOldPen);
}
if(pOldBrush!=NULL)
{
dc.SelectObject(pOldBrush);
}
ASSERT(pOldBrush->DeleteObject() );
ASSERT(pOldPen->DeleteObject() );
ASSERT(orangePen.DeleteObject() );
}