Re: MFC Custom Control in a MFC DLL
HI Joe,
I studied a bit on this thing about ScrollWindow, PolyLine and the
flicker thing....and I got this point:
lemme guess using ScrollView means preventing flickering, even if I
use CMemDC which as documented it should reduce flickering effect,
when I am redesign the entire client area; indeed it should be enough
to redesign a single object in the client area without using
ScrollWindow since it's a little object with a very limited flicker
which would be like invisible to the eye... right?...
In fact with this code I implemented:
void MyDLL::OnTimer(UINT TimerVal)
{
BOOL timerstate;
// ****** stopping timer ******
timerstate = TRUE;
if (!KillTimer(iTimerVal))
{
// message
MessageBox(_T("Unable to stop timer!"), _T
("IDT_TIMER_0"), MB_OK|MB_ICONSTOP|MB_SYSTEMMODAL);
timerstate = FALSE;
}
// ****** processing event ******
gridOffset++;
if (gridOffset > 12.5)
gridOffset = 0;
Invalidate();
// ****** restart timer *******
if (timerstate)
{
iTimerVal = SetTimer(IDT_TIMER_0, 1000, 0);
}
// call base class handler
CWnd::OnTimer(TimerVal);
}
void MyDLL::OnDraw(CDC* pDC)
{
CMemDC mDC(pDC);
//EraseBkgnd(mDC);
CRect rect;
GetClientRect(rect);
// For now, background black fixed
mDC->FillRect(rect, CBrush::FromHandle((HBRUSH)GetStockObject
(BLACK_BRUSH)));
// ********** Background ***********
// Grid
if (bActivateGrid)
{
CPen qLinePen(PS_SOLID, 1, RGB(0,139,0));
mDC->SelectObject(&qLinePen);
// Grid - Horizontal lines
mDC->MoveTo(1, 0);
mDC->LineTo(rect.Width(), 0);
int height = rect.Height();
int maxlines = height / 12.5;
for (int i=1;i<=maxlines;i++){
int y_axis = i * 12.5;
if (y_axis <= rect.Height()) {
mDC->MoveTo(1, y_axis);
mDC->LineTo(rect.Width(), y_axis);
}
}
// Grid - Vertical lines
mDC->MoveTo(0, 0);
mDC->LineTo(0, rect.Height());
int width = rect.Width();
maxlines = width / 12.5;
for (int i=1;i<=maxlines;i++){
int x_axis = (i * 12.5) - gridOffset;
if (x_axis <= rect.Width()) {
mDC->MoveTo(x_axis, 1);
mDC->LineTo(x_axis, rect.Height());
}
}
}
}
here actually I'm redrawing the entire client area so it produces a
flicker even if I am using CMemDC because on this drawing I can
understand I'm doing lots of operations in a single draw...
Indeed, if I got it good as you are explaining, using ScrollWindow
would be like a single operation for almost entire part of client area
which would be very fast and then draw only next values in that little
remaining part at right edge.
The only thing I'm thinking at now is when I'm resizing which I think
it wouldn't really flicker redrawing the entire window client is about
to know what value from I have to draw left to right since in a
complete redraw due to resizing would draw from left to right....
Am I right?... What do you suggest in this case?....
Ciao!
Luigi