谁有例子?

解决方案 »

  1.   

    SetTimer( )
    Invalidate( )
      

  2.   

    先在对话框中加一个按钮,ID IDC_OWNER,把自画属性选上
    在对话框的WM_DRAWITEM中加如下代码.
    void CCsdnDlg::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct) 
    {
    if(IDC_OWNER == nIDCtl)
    {
    CDC dc;
    dc.Attach(lpDrawItemStruct->hDC);
    CRect r;
    GetDlgItem(IDC_OWNER)->GetClientRect(&r);
    CTime t =CTime::GetCurrentTime();//避免随机数相同,根据当前时间的秒数,先调用几次
    int n = t.GetSecond();
    for(int i = 0 ; i < n ; i++)
    rand();

    int maxX = r.right;
    int maxY = r.bottom;
    CPoint beginPoint,endPoint;
    beginPoint.x = rand()%maxX;
    beginPoint.y = rand()%maxY;
    endPoint.x   = rand()%maxX;
    endPoint.y   = rand()%maxY; dc.MoveTo(beginPoint);
    dc.LineTo(endPoint);
    } CDialog::OnDrawItem(nIDCtl, lpDrawItemStruct);CCsdnDlg::OnInitDialog()
    {
    CDialog::OnInitDialog();
    SetTimer(1,1100,NULL);...
    }
    对话框的WM_TIMER中
    void CCsdnDlg::OnTimer(UINT nIDEvent) 
    {
    Invalidate(true);
    CDialog::OnTimer(nIDEvent);
    }
    }