0
votes

When I doubleclick in Static Control, I will draw ellipse in Static Control in the position of mouse.(MFC); But, It apears that: suprised

And My code:

void CTreeShowLabel::OnLButtonDblClk(UINT nFlags, CPoint point)

{

//设置画笔

COLORREF black = RGB(255, 0, 0);

CPen pen(PS_SOLID, 1, black);

CClientDC Dc(GetDlgItem(IDC_TREESTATIC));

Dc.SelectObject(pen);

//在鼠标处画图
CPoint curPos;
GetCursorPos(&curPos);

CPoint point1(0,0);
point1.x = curPos.x - 50;
point1.y = curPos.y - 50;

CPoint point2(0,0);
point2.x = curPos.x + 50;
point2.y = curPos.y + 50;

    //画圆
Dc.Ellipse(CRect(point1, point2));
CStatic::OnLButtonDblClk(nFlags, point);

}

About the Circle is terrible.

1

1 Answers

0
votes

It doesn't seem a good idea to draw the ellipse in the OnLButtonDblClk event catcher. You should create your own class derived from CStatic and overwrite the OnPaint method.

Then from the event catcher you should tell the static that it has to draw the ellipse and where (for instance two member variables: bool m_bDraw / CPoint m_DrawingPoint) and call Invalidate in the Static.