在编程序时用到了定时器,但是在运行中会闪屏 ,请问如何解决?小弟的毕业设计阿,就这点没解决了,谢谢各位

解决方案 »

  1.   

    哥哥,小弟觉得比较抽象下面是我的源程序我得想法是:当受到服务器信息时客户端的定时器起作用
     
    void CClientDlg::ReceiveMsg()
    {
    CMsg msg;
    TRY
    {
    //接收消息
    msg.Serialize(*m_pArchiveIn);
    while (!msg.m_msgList.IsEmpty())
    {
    CString strTemp;
    //获取消息内容
    strTemp=msg.m_msgList.RemoveHead();//从列表头开始移动,
    //但是必须确保类标不空,同时可以用IsEmpty函数来检验

    // 是不是空的
    //显示消息

    SetTimer(1,100,NULL);

    //定时器的选择100代表毫秒

    DisplayMsg(strTemp);


    }
    }
    CATCH(CFileException,e)
    {
    //错误处理
    m_bAutoChat=FALSE;
    msg.m_bClose=TRUE;
    m_pArchiveOut->Abort();
    CString strTemp;
    strTemp="服务器重置连接!";
    DisplayMsg(strTemp);
    strTemp="连接关闭!";
    DisplayMsg(strTemp);
    }
    END_CATCH
    if (msg.m_bClose)
    {
    //处理服务器关闭的消息
    delete m_pArchiveIn;
    m_pArchiveIn=NULL;
    delete m_pArchiveOut;
    m_pArchiveOut=NULL;
    delete m_pFile;
    m_pFile=NULL;
    delete m_pSocket;
    m_pSocket=NULL;
    }
    }下面是定时器:void CClientDlg::OnTimer(UINT nIDEvent) 
    {
    // TODO: Add your message handler code here and/or call default

    RECT rect;

    ::GetClientRect(this->m_hWnd,&rect);

       if(rect.right<train2.star.x)
            { 
    train2.start.x=540;
    train2.start.y=226;
    }
    InvalidateRect(CRect(0,120,550,230));//有人说可以用这个函数消除,但是只是这个框外的没有闪,而我要显得图像含比较宽,所以没有办法,谢谢各位了


    }
      

  2.   

    //重绘屏幕时不刷系统默认的灰色背景
    BOOL CGameClientDlg::OnEraseBkgnd(CDC* pDC)
    {
    // TODO: 在此添加消息处理程序代码和/或调用默认值
    return TRUE;
    //return CDialog::OnEraseBkgnd(pDC);
    }
      

  3.   

    Invalidate(FALSE)                             ?
    InvalidateRect(CRect(0,120,550,230),FALSE);   ???
    不知道行不行