Invalidate()和child_wnd_name.InvalidateRect(& rect)会导致不同的结果

时间:2017-11-14 12:19:49

标签: winapi mfc

我正在编写一个基于对话框的应用程序,它有一个静态控件,一个按钮和两个编辑控件。静态类型为class MyStatic : public CStatic,其OnPaint()定义如下:

void MyStatic::OnPaint()
{
    CPaintDC dc(this);
    int Row = pBGDlg->iRow;          //pBGDlg is a pointer to the dialog
    int Column = pBGDlg->iColumn;    //iRow and iColumn are variables of the two edit controls
    int RowHei = pBGDlg->iRowHei;
    int ColumnWid = pBGDlg->iColumnWid;

    if (bBuPressed)
    {
        for (int i = 0; i <= Row; ++i)
        {
            dc.MoveTo (0, i * RowHei);
            dc.LineTo (Column * ColumnWid, i * RowHei);
        }
    }

每当用户输入两个整数并按下按钮时,应用程序将在静态

上绘制相应的行
void CProjDlg::OnClickedIdpreview()
{
    UpdateData ();
    mystatic.GetClientRect (&rtStatic);        //mystatic is the name of the static
    iRowHei = (rtStatic.Height () - 1) / iRow;  
    iColumnWid = (rtStatic.Width () - 1) / iColumn;

    mystatic.bBuPressed = true;
    Invalidate ();  
    UpdateWindow ();
}

例如:Input 4 to the 1st edit control,然后是input 1 to the 1st edit control。但是,如果我分别用mystatic.InvalidateRect(&rtStatic);mystatic.UpdateWindow();替换Invalidate();UpdateWindow();,则应用程序无法删除以前的结果。例如:Input 4 to the 1st edit control,然后是input 5 to the 1st edit control。我无法弄清楚为什么第二种方法失败了。有人可以帮我解释一下吗?非常感谢你。

0 个答案:

没有答案