Home > Software engineering >  In the vs2017 wrote a drawing program, why the mouse click click, drag, line painting not to come ou
In the vs2017 wrote a drawing program, why the mouse click click, drag, line painting not to come ou

Time:12-05

Ask people using the vc, I use c + + in the vs2017, wrote a simple single document of the project, it is responsible for the painting line, arc, the function of line drawing, I define a class that defines the left key click inside, mouse movement of virtual function, where the implementation I overloaded the class, when I was in the View, the mouse click click, why line painting not to come out? Code is no problem,
Choose the toolbar's straight line, the corresponding code:
//draw a straight line
Void CmyDrawView: : OnShapeLine ()
{
If (NULL!=pCTool)
{
The delete pCTool;
PCTool=NULL;
}

M_Rmenu=4;
PCTool=new CLine ();
PCTool - & gt; SetPenColor (m_pencolor);
PCTool - & gt; SetPenStyle (m_penstyle);
PCTool - & gt; SetPenWidth (m_penwidth);
}
The mouse click, mouse the left key press code:
Void CmyDrawView: : OnLButtonDown (UINT nFlags, CPoint point)
{
//TODO: add the message handler code and/or invoke the default
If (pCTool!=NULL)
{
: : CClientDC dc (this);
PCTool - & gt; OnLButtonDown (point, datemanage, dc);
}
//the CView: : OnLButtonDown (nFlags, point);
}
Release the mouse code
Void CmyDrawView: : OnLButtonUp (UINT nFlags, CPoint point)
{
//TODO: add the message handler code and/or invoke the default
If (pCTool!=NULL)
{
: : CClientDC dc (this);
PCTool - & gt; OnLButtonUp (point, datemanage, dc);
}
The CView: : OnLButtonUp (nFlags, point);
}
Drag the code
Void CmyDrawView: : onm ouseMove (UINT nFlags, CPoint point)
{
//TODO: add the message handler code and/or invoke the default
If (pCTool!=NULL)
{
CClientDC dc (this);
PCTool - & gt; onm ouseMove (point, dc);
}
The CView: onm ouseMove (nFlags, point);
}
I don't know what reason?

CodePudding user response:

I don't see any void CMyView: : ontouch * pDC (CDC)

Void CMyView: : ontouch * pDC (CDC)
{
PDC - & gt; SelectStockObject (BLACK_PEN);

BOOL first=TRUE;
The POSITION pos=m_points. GetHeadPosition ();
if(! Pos)
{
return;
}
While (pos!=NULL)
{
CMyPoint * p=(CMyPoint *) m_points GetNext (pos);
If (first) {pDC - & gt; MoveTo (p - & gt; M_location); The first=FALSE; }
PDC - & gt; The LineTo (p - & gt; M_location);
};
}

CodePudding user response:

CObList has m_points;
In the h

CodePudding user response:

In the parent class already overloaded ontouch () function

CodePudding user response:

Set a breakpoint or add TRACE, debug see click, when the mobile is according to your way of thinking, the parameter?

CodePudding user response:

reference 4 floor zgl7903 response:
set a breakpoint or add TRACE, debug see click, when the mobile is according to your way of thinking, the parameters for?

Breakpoint is set, I'm OK, don't know what happened?