解决方案 »

  1.   

    贴一下pDc 的详细信息。和它涉及到的操作
      

  2.   

    CDC *pDc = GetDC(); 就是在前面申请一个dc。别的没有了
      

  3.   

    /定时器绘制图片。在现有灯具上在绘制一个图片。形成闪烁效果
    void CLEESView::ListenFirePicShowThread()
    {
    CLEESDoc *pdoc = GetDocument(); //CLEESDoc *pdoc = GetDocument(); std::vector<FlatDeiveInfo*>::iterator iter;
    //TCHAR Path[200];
    //memset(Path,0,200);
    //CString strPath; ////::GetCurrentDirectory(strPath);
    //::GetModuleFileName(NULL,Path,sizeof(Path));
    //strPath = Path;
    //strPath.ReleaseBuffer();
    //int nPos;
    //nPos=strPath.ReverseFind(_T('\\'));
    //strPath =strPath.Left (nPos); //Graphics buffer(pView->m_hWnd); if (pdoc->FlatDevice.size() <= 0)
    {
    return ;
    //return;
    }
    CBmpProc pic; pic.LoadFromResourceID(IDB_BITMAP1,NULL); //EnterCriticalSection(&g_cs); for (iter = pdoc->FlatDevice.begin() ; iter != pdoc->FlatDevice.end(); ++iter)
    {
    if (pdoc->LampsJudge((*iter)->DeviceTypeNum) == true)
    {
    //如果是故障则不进行闪动提示
    //if ((*iter)->State == NORMAL)
    //{
    // continue;
    //}
    //如果是导光流不提示闪烁
    if ((*iter)->GuideFlowGroup > 0)
    {
    continue;
    } CString strDevicePath;
    //获取当前平面坐标。把当前的屏幕坐标转换成逻辑坐标。因为存在,平面移动
    //对比当前的屏幕坐标和逻辑坐标。如果逻辑坐标在当前屏幕显示区域内。则绘图。否则不绘图
    //绘图坐标把当前的设备坐标在转换成当前屏幕坐标进行绘图
    RECT rect;
    GetClientRect(&rect);
    //GetClientRect(&rect);
    CPoint point;
    CPoint point2;
    CPoint DevicePoint;
    DevicePoint.x = (*iter)->X;
    DevicePoint.y = (*iter)->Y; point.x = rect.left;
    point.y = rect.top;
    point2.x = rect.right;
    point2.y =rect.bottom; CClientDC dc(this);
    OnPrepareDC(&dc); //CClientDC dc(this);
    //OnPrepareDC(&dc); dc.DPtoLP(&point);
    dc.DPtoLP(&point2);
    dc.LPtoDP(&DevicePoint); int x =(*iter)->X;
    int y=(*iter)->Y; CDC *pDc = GetDC();
    //CDC *pDc = GetDC();
    if (x > point.x && x< point2.x && y > point.y && y < point2.y)
    {
    CRect srcRect,dstRect;
    //srcRect.IsRectNull();
    srcRect.SetRectEmpty();
    dstRect.SetRectEmpty();

    if ((*iter)->State == NORMAL)
    {
    //continue;
    //strDevicePath = FindPicName((*iter)->NormalDir,iter);
    srcRect =FireShowPic(pDc,(*iter)->DeviceTypeNum,(*iter)->Angle,(*iter)->NormalDir);
    }
    if ((*iter)->State == URGENT)
    {
    if ((*iter)->Direction != 0)
    {
    //strDevicePath = FindPicName((*iter)->Direction,iter);
    srcRect =FireShowPic(pDc,(*iter)->DeviceTypeNum,(*iter)->Angle,(*iter)->Direction);
    }
    else
    {
    //strDevicePath = FindPicName((*iter)->UrgentDir,iter);
    srcRect =FireShowPic(pDc,(*iter)->DeviceTypeNum,(*iter)->Angle,(*iter)->UrgentDir); } } if (srcRect.IsRectEmpty())
    {
    continue;
    } //srcRect =FireShowPic(pDc,(*iter)->DeviceTypeNum,(*iter)->Angle,(*iter)->Direction);
    dstRect = DrawPicPonit((*iter)->DeviceTypeNum,(*iter)->Angle); //srcRect =FireShowPic(pDc,(*iter)->DeviceTypeNum,(*iter)->Angle,(*iter)->Direction);
    //dstRect = DrawPicPonit((*iter)->DeviceTypeNum,(*iter)->Angle); dstRect.top = DevicePoint.y + dstRect.top; 
    dstRect.bottom = DevicePoint.y+dstRect.bottom;
    dstRect.left = DevicePoint.x+ dstRect.left ;
    dstRect.right = DevicePoint.x+ dstRect.right; CBmpProc *pBmp = (CBmpProc*)new(CBmpProc);
    pBmp->LoadFromObject(pic,&srcRect);
    if (pDc != NULL)
    {
    pBmp->Draw(*pDc,&dstRect);

    ReleaseDC(pDc);
    }
    delete (CBmpProc*)pBmp;
    }
    } }
    //LeaveCriticalSection(&g_cs);
    Invalidate(false);
    return ;
      

  4.   

    昨天又跟程序发现加了句 ASSERT(pic.IsValid()); 在CBmpProc *pBmp = (CBmpProc*)new(CBmpProc);
    这句好像就崩了。晕了!!!