80 likes | 172 Views
This presentation covers the implementation of drawing applications using mouse events in C++. Specifically, it demonstrates how to manage mouse button interactions and draw lines on the client area of a window using MFC (Microsoft Foundation Classes). The code examples show how to handle left mouse button clicks, track mouse movements, and update the drawing dynamically, allowing for both horizontal and vertical line drawing capabilities. Key techniques involve using device contexts and pens to render graphics on windows.
E N D
PRESENTATION Presented to: Ma’am Sadaf Majeed Sial Presented by: M.Amjad Rahim BSIT-08-09 5th Semester
Program No. 7 Public: Myframe() { Create(0, “Click L Button of Mouse in Client area”); } Void OnLButtonDown(UNIT flag, Cpoint pt) { Startpoint=endpoint=pt; SetCapture(); } Continue…..
Void On MouseMove (UNIT flag, Cpoint pt) { CClientDC d (this); If(flag==MK_LBUTTON) { d.SetROP2(R2_NOTXORPEN); // erase line d.MoveTo(startpoint); d.LineTo(endpoint); //draw line d.MoveTo(startpoint); d.LineTo(pt); Endpoint=pt; } } Continue…..
Void OnLButtonUp (UNIT flag, CPoint pt){ CClientDC d (this); d.SetROP2(R2_COPYPEN); d.MoveTo (startpoint); d.LineTo (endpoint); ::RealseCapture(); } DECEAR_MESSAGE_MAP() };
Program No.8 Public: Myframe() { Create (0,”Horizental or Vertical \lines”); D=new CClentDc (this); Mypen.createPen(PS_SOLID,1,RGB(255,0,0)); d->SelectObject (&mypen); } Void OnButtonDown (UNIT flag, CPoint pt) { Oldpoint=point1=pt; } Continue…..
Void OnMouseMove (UNIT flag, CPoint pt { If(flags==(MK_LBUTTON | MK_SHIFT)) { If(abs(pt.y-point1.y)>abs(pt.x-point1.x)) Pt.x=pint1.x; Else Pt.y=point1.y; d->SetROP2(R2_NOTXORPEN); d->MoveTo (point1); d->LineTo (oldpoint) d->MoveTo (poin1); d->LineTo (pt); oldpoint=pt; } Continue…..
If(flags==MK_LBUTTON) { d->setROP2(R2_NOTXORPEN); d->MoveTo (point1); d->LineTo (oldpoint); d->MoveTo (point); d->LineTo (pt); oldpoint=pt; } } Continue…..
Viod OnButtonUp (UNIT flags,CPoint pt) { d->SetROP2(R2_COPYPEN); d->MoveTo (point); d->LineTo(oldpoint); } DECLARE_MESSAGE_MAP() };