is it true

Dear All,
I have designed one FormView, and i want to use OnLButtonDown() to update the graph on the Form, but i use the code.

void CRTForm::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
int white = RGB(255,255,255);

CPaintDC dc(this); // device context for painting
double m_dfMinX;
double m_dfMaxX;
double m_dfMinY;
double m_dfMaxY;
double m_dfDeltaX=1;
int xoffs=40;
int yoffs=10;

CRect rect1;
this->GetClientRect(&rect1);
//To make the background of rect1 and text are white
CBrush brBackground(white);
// FillRect(dc, rect1, brBackground);
// SetBkColor(dc,white);
m_dfMinX = rect1.left;
m_dfMaxX = rect1.right;
m_dfMinY = rect1.top;
m_dfMaxY = rect1.bottom;

RECT rect;
rect.left=(long)(m_dfMinX+xoffs);
rect.top=(long)(m_dfMinY+yoffs+20);
rect.bottom=(long)(m_dfMaxY-(m_dfMaxY-m_dfMinY)*5.7/10-yoffs+200);
rect.right=(long)(m_dfMaxX-xoffs);

CPen solidBluePen(PS_SOLID, 1, RGB(0, 0, 255));
CPen solidBlackPen(PS_SOLID, 1, RGB(0, 0, 0));
CPen dotPen(PS_DOT, 1, RGB(0, 0, 0));

CPen *pOldPen = dc.SelectObject(&solidBluePen);
dc.TextOut(xoffs+400,0,"Power Spectral");
pOldPen =dc.SelectObject(&solidBlackPen);
//to plot the rectangle boundary
dc.MoveTo(int(rect.left),int(rect.top));
dc.LineTo(int(rect.right),int(rect.top));
dc.LineTo(int(rect.right),int(rect.bottom));
dc.LineTo(int(rect.left),int(rect.bottom));//rect.bottom is the bottom y value of the rect
dc.LineTo(int(rect.left),int(rect.top));

CFormView::OnLButtonDown(nFlags, point);
}

to draw one rectangle on the Form, it cannot sucessful. To draw the graph on Form, does it need to put all code into OnDraw() or Onpaint() only? is it true?
[1958 byte] By [lwong] at [2007-11-18 17:45:43]
# 1 Re: is it true
To draw the graph on Form, does it need to put all code into OnDraw() or Onpaint() only? is it true?

No, it is not mandatory but it is highly recommended. In OnLButtonDown you should compute ( or better yet put the code in a separate method) the rect you need to draw. Save all the data required for drawing in member variables and then update the view ( see UpdateWindow).

The actual drawing should be placed in the OnPaint. There you can use the data previously computed.
PadexArt at 2007-11-11 1:25:43 >
# 2 Re: is it true
Also for a form view you don't draw in response to WM_PAINT
and you should not be using a CPaintDC context outside of
a WM_PAINT Handler.
souldog at 2007-11-11 1:26:40 >