【发布时间】:2025-12-29 12:10:17
【问题描述】:
我尝试在一个名为IDC_RESULT的静态文本控件中绘制。当我单击确定按钮时,静态文本会根据我选择的形状显示不同的图片。所以我声明了三个bool变量:isLine,is Rect和isEllipse,每次选择 Lien 单选框时,我都会让布尔变量 isLine 为 true,其他为 false,与 Rectangle 和 Ellipse 相同。
这是我的代码:
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();
}
}
下面的功能与确定按钮相关联:
void CDrawDlg::OnBnClickedOk()
{
Invalidate(false);
}
问题是:当我选择矩形并单击确定按钮绘制矩形时,如何擦除静态文本控件中的线条,但我无法擦除线条。
【问题讨论】:
标签: visual-c++ mfc draw invalidation