Create a project with a single document structure
HDC:
First, add windows message handler in the cyourclassview class. One is lbuttondown and the other is lbuttonup. Add the member variable m_ptorigin to record the initial vertex position.
Initialize the m_ptorigin variable in the view struct:
Cyourclassview: cyourclassview ()
{
// Todo: Add construction code here
M_ptorigin = 0;
}
Add the code to the lbuttondown function:
Void cyourclassview: onlbuttondown (uint nflags, cpoint point)
{
// Todo: add your message handler code here and/or call default
M_ptorigin = point;
Cview: onlbuttondown (nflags, point );
}
Add code in lbuttonup, first use HDC:
Void cyourclassview: onlbuttonup (uint nflags, cpoint point)
{
// Todo: add your message handler code here and/or call default
HDC;
HDC =: getwindowdc (m_hwnd );
Movetoex (HDC, m_ptorigin.x, m_ptorigin.y, null );
Lineto (HDC, point. X, point. y );
: Releasedc (m_hwnd, HDC );
Cview: onlbuttonup (nflags, point );
}
Use CDC:
Void cyourclassview: onlbuttonup (uint nflags, cpoint point)
{
// Todo: add your message handler code here and/or call default
CDC * PDC = getdc ();
PDC-> moveTo (m_ptorigin );
PDC-> lineto (point );
Releasedc (PDC );
Cview: onlbuttonup (nflags, point );
}
Use cclientdc:
Void cyourclassview: onlbuttonup (uint nflags, cpoint point)
{
// Todo: add your message handler code here and/or call default
Cclientdc DC (this );
DC. moveTo (m_ptorigin );
DC. lineto (point );
Cview: onlbuttonup (nflags, point );
}
Use cwindowdc:
Void cyourclassview: onlbuttonup (uint nflags, cpoint point)
{
// Todo: add your message handler code here and/or call default
Cwindowdc DC (this );
DC. moveTo (m_ptorigin );
DC. lineto (point );
Cview: onlbuttonup (nflags, point );
}