简体   繁体   中英

Show information on a dialog in MFC

I am doing a small drawing tool with MFC.

When button down capture the original point, when button up capture the new point, and then draw a line from the original point to the new point.

I have already created a dialog. But I don't know how to display both the original point and the new point on it while button up.

Code of drawing line and showing dialog as below:

void CDrawView::OnLButtonDown(UINT nFlags, CPoint point)
{
    m_ptOrigin = point;

    CView::OnLButtonDown(nFlags, point);
}

void CDrawView::OnLButtonUp(UINT nFlags, CPoint point)
{
    CDC *pDC = GetDC();
    pDC->MoveTo(m_ptOrigin);
    pDC->LineTo(point);
    ReleaseDC(pDC);

    CArgDlg object;  // Jump out a dialog
    object.DoModal();

    CView::OnLButtonUp(nFlags, point);
}

Can some one help me?

Move the drawing code from the button handlers out to OnDraw().

I assume you want to just display the values of the two points in the dialog? Declare two member variables m_pt1 and m_pt2 in the dialog class and fill your static/edit controls from these values in OnInitDialog() .

void CDrawView::OnLButtonUp(UINT nFlags, CPoint point)
{   m_ptEnd = point; // new member variable
    CRect rc(m_ptOrigin, m_ptEnd);
    InvalidateRect(&rc); // will invoke OnDraw()

    CView::OnLButtonUp(nFlags, point);

    CArgDlg object;  // Jump out a dialog
    object.m_pt1 = ptOrigin;
    object.m_pt2 = m_ptEnd;
    object.DoModal();
}

Override OnDraw(), don't start drawing inside button handlers. The point is that the underlying win32 framework keeps track of when and what needs to be drawn and you draw it when it asks you to draw (ie in OnDraw()).

BTW: I'm not sure what you want to achieve with the dialog, because you are at the moment drawing the line on the view that contains the button handlers, not in the dialog.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM