1
votes

I try to draw in a static text control named IDC_RESULT.When I click the OK button, the static text will display different picture according to the shape I selected.So I declare three bool variable: isLine ,is Rect and isEllipse, everytime when I choose Lien radio box, I make the bool variabel isLine be true and the others be false, the same as Rectangle and Ellipse.

This is my code:

void CDrawDlg::OnPaint()
{

    CWnd* pWnd = (CWnd*)GetDlgItem(IDC_RESULT); 
    CPaintDC dcPaint(pWnd);
    CPen pen(PS_SOLID,2,RGB(0,0,0));   
    dcPaint.SelectObject(&pen);

    CRect  rect;
    pWnd->GetClientRect(&rect);

    if(isLine)
    {   
        dcPaint.MoveTo(10,150);
        dcPaint.LineTo (350,150);

    }

    if(isRect)
    {
        dcPaint.Rectangle(50, 100, 300, 200);
    }

    if(isEllipse)
    {
        doSomething;
    }

    ReleaseDC(&dcPaint);

    if (IsIconic())
    {
        CPaintDC dc(this); 

        SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

    int cxIcon = GetSystemMetrics(SM_CXICON);
    int cyIcon = GetSystemMetrics(SM_CYICON);
    CRect rect;
    GetClientRect(&rect);
    int x = (rect.Width() - cxIcon + 1) / 2;
    int y = (rect.Height() - cyIcon + 1) / 2;

    dc.DrawIcon(x, y, m_hIcon);

}
else
{
    CDialogEx::OnPaint();
}
}

And the function below associate with the OK button:

void CDrawDlg::OnBnClickedOk()
{
     Invalidate(false);
}

The question is: How to erase the line in the static text control when I select Rectangle and click the OK button to draw a rectangle,but I can't erase the line.

1

1 Answers

0
votes

The parameter to Invalidate (bErase) controls whether or not the background within the update region should be erased. Since you passed false it isn't. Pass TRUE instead.

As an aside, you should use TRUE/FALSE instead of true/false as arguments to MFC methods. Even though the types are compatible they are still different.