除非我制作“静态 CPaintDC dc(this);” 线不会画?但这不好,因为它最终会出错,图形也不会保留在屏幕上。
不知道我做错了什么
注意:我有一个计时器,它每 100 毫秒调用一次(x 和 y 递增)thx
void CGraphicsDlg::OnPaint()
{
CString s;
CPaintDC dc(this);// device context for painting
if (IsIconic())
{
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
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;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else if(x==0)
{
s.Format("%d", x);
edXa->SetWindowText(s);
dc.MoveTo(20,400);
}
else if (x>0){
s.Format("%d", x);
edXb->SetWindowText(s);
dc.LineTo(20 + x, 40); // doesn't draw unless I make "static CPaintDC dc(this);" <- which will error out
}
CDialog::OnPaint();
}
void CGraphicsDlg::OnTimer(UINT nIDEvent)
{
if(nIDEvent==1){
srand( (unsigned)time( NULL ) );
//y = rand() % 100;
y++;
x++;
OnPaint();
}
}