Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Drawing rectangles 1

Status
Not open for further replies.

Leibnitz

Programmer
Apr 6, 2001
393
CA
*********************************************************************************
i'm trying to make some drawing with the mouse,for that purpose i have wrote the following code but there is no results displayed on the window.I can't find what's wrong with the code:

Code:
void CResizableRectanglesView::OnLButtonDown(UINT nFlags, CPoint point) 
{
	drawing = true;
	beginPoint = point;
	oldPoint = beginPoint;
	CView::OnLButtonDown( nFlags, point );
}

void CResizableRectanglesView::OnLButtonUp(UINT nFlags, CPoint point) 
{
	if(drawing)
	{
		drawing = false;
		CPaintDC dc(this);
		ropOld = dc.SetROP2(R2_NOTXORPEN);
		thisPoint = point;
		dc.Rectangle( beginPoint.x, beginPoint.y, oldPoint.x, oldPoint.y );
		dc.SetROP2(ropOld);
		dc.Rectangle( beginPoint.x, beginPoint.y, thisPoint.x, thisPoint.y );
	}

	CView::OnLButtonUp( nFlags, point );
}

void CResizableRectanglesView::OnMouseMove(UINT nFlags, CPoint point) 
{
	if( drawing )
	{
		CPaintDC dc(this);
		ropOld = dc.SetROP2(R2_NOTXORPEN);
		thisPoint = point;
		dc.Rectangle( beginPoint.x, beginPoint.y, oldPoint.x, oldPoint.y );
		dc.Rectangle( beginPoint.x, beginPoint.y, thisPoint.x, thisPoint.y );
		oldPoint = thisPoint;
		dc.SetROP2(ropOld);
	}

	CView::OnMouseMove( nFlags, point );	
}
[\code]
 
Try this instead :-
void CResizableRectanglesView::OnDraw(CDC* pDC)
{
CTest01Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
if( drawing == true )
{
CPen penBlack;
penBlack.CreatePen(PS_SOLID, 3, RGB(0, 0, 0));
CPen* pOldPen = pDC->SelectObject(&penBlack);
pDC->Rectangle( beginPoint.x, beginPoint.y, thisPoint.x, thisPoint.y );
pDC->SelectObject(pOldPen);
}
}

void CResizableRectanglesView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
drawing = true;
beginPoint = point;
oldPoint = beginPoint;
CView::OnLButtonDown(nFlags, point);
}

void CResizableRectanglesView::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default

if( drawing == true)
{
thisPoint = point;
Invalidate();
}

CView::OnMouseMove(nFlags, point);
}

void CResizableRectanglesView::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(drawing == true)
{
thisPoint = point;
drawing = false;
Invalidate();
}

CView::OnLButtonUp(nFlags, point);
}
O.B
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top