Ed wrote:
I use the routine below to draw a bargraph in a IDC_PIC window when a
button is clicked.
This routine workse fine but when the user opens another window that
overlaps this one
and then returns focus to this window the part of the bargraph that was
covered is blank.
Please show me how to fix this so when focus is returned to my app it is
redrawn.
bool CEcolorDlg::drawbars1()
{
CRect cr;
CBrush yel(RGB(255,255,213));
CBrush blu(RGB(114,120,141));
CBrush blk(RGB(0,0,0));
int c=15, b=5, d, e=0, a;
GetDlgItem(IDC_PIC)->GetClientRect(cr);
CWnd* pWnd=GetDlgItem(IDC_PIC);
pControlDC=pWnd->GetDC();
d = (cr.Width()-20)/numkeys;
//draw background
pControlDC->SelectObject(blu);
pControlDC->Rectangle(0,0,cr.Width(), cr.Height());
//draw 50% grid line
pControlDC->SelectObject(blk);
pControlDC->Rectangle(1, (cr.Height()/4), cr.Width()-1,
(cr.Height()/4)+1);
pControlDC->Rectangle(1, (cr.Height()/2), cr.Width()-1,
(cr.Height()/2)+1);
pControlDC->Rectangle(1, (cr.Height()/2)+(cr.Height()/4), cr.Width()-1,
(cr.Height()/2)+(cr.Height()/4)+1);
pControlDC->SelectObject(yel);
for (b=0; b<numkeys; b++)
{
a = ((bar[b] * 10) / 10)+1;
pControlDC->Rectangle (c, cr.Height(), c+3, cr.Height()-a);
c+=d;
}
pControlDC->SelectStockObject(BLACK_BRUSH);
return true;
}
Thanks in advance
Ed:
Make a derived picture control class and put the bargraph drawing code in
its OnPaint() handler.
David Wilkinson