简体   繁体   English

在MFC中显示对话框的信息

[英]Show information on a dialog in MFC

I am doing a small drawing tool with MFC. 我正在用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(). 将绘图代码从按钮处理程序移出到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() . 在对话框类中声明两个成员变量m_pt1m_pt2 ,并从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. 覆盖OnDraw(),不要开始在按钮处理程序内绘图。 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()). 关键是底层的win32框架会跟踪需要绘制的时间和内容,并在它要求您绘制时绘制它(即在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. 顺便说一句:我不确定你想用对话框实现什么,因为你现在正在包含按钮处理程序的视图上画线,而不是在对话框中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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