以下是绘制部分的程序,如果用采集到的动态数据pData,则能正常运行,而如果自己写了一组静态数据biodat给pData赋值,则绘制完毕后会弹出“0x004038b2”指令引用的"0x00133000"内存。该内存不能为"read"对话框。是由于自己写的数组长度有限的原因吗?先谢谢各位大神了!我最终的目的是要从二进制文件读入一组数据,再将其绘制出来,所以想改改这个绘制动态数据的程序。void CRecordHWndDlg::DrawWave(CDC *pDC,PBYTE pData,DWORD dwDrawLength)// PBYTE8位 DWORD32位
{
if(!bEnding)
{
    CWnd* pWnd = GetDlgItem(IDC_SHOW);
    CRect rect;
    pWnd->GetClientRect(rect);
    pDC->Rectangle(rect);

//座标
    pDC->MoveTo(0,rect.Height()/2);
    pDC->LineTo(rect.Width(),rect.Height()/2);
    pDC->MoveTo(10,0);
    pDC->LineTo(10,rect.Height());
//?????
    pDC->SetMapMode(MM_ANISOTROPIC);//does not change the current window or viewport settings
    
//Sets the x- and y-extents of the window associated with the device context
pDC->SetWindowExt(dwDataLength,256); //Sets the x- and y-extents of the viewport of the device context
     pDC->SetViewportExt(rect.Width(),-rect.Height()); //Sets the viewport origin of the device context
     pDC->SetViewportOrg(0,rect.Height()/2);
/*   设置画线的线型,宽度和颜色    */
    CPen pen;
     pen.CreatePen(PS_SOLID,0,RGB(0,0,255));//RGB(255,0,0));     CPen *pOldPen = pDC->SelectObject(&pen);
//Draw Wave here

int i;
int biodata[160] = {0,0,0,0,2,     5,8,10,13,14,      14,14,12,11,9,     7,5,4,2,1,
1,0,0,1,1,     1,1,1,2,2,         2,3,3,3,3,         3,3,3,3,
3,3,6,11,20,   33,51,72,91,103,   105,96,77,53,27,   5,-11,-23,-28,-28,
-23,-17,-10,-5,-1,  0,1,2,1,1,         1,1,0,0,0,         0,0,0,0,0, 
0,0,0,0,1,     1,2,2,3,4,         4,4,5,6,7,         8,8,9,10,10,
11,11,12,12,   12,13,14,16,18,    20,22,24,27,29,    31,34,37,39,42,
44,47,49,52,54, 55,56,57,57,58,58, 57,57,56,56,54,   52,50,47,43,40,
36,33,29,26,23, 20,17,14,12,10,   8,7,5,3,2,         1,1,0,0,0};
 for(i=0;i<(unsigned short)dwDrawLength;i++)
 {
if(i>160)
{
pData[i] =0;
} pData[i] = biodata[i]/5000;
pDC->MoveTo(i,pData[i]);
pDC->LineTo(i+1,pData[i+1]);
 }
   
   pDC->SelectObject(pOldPen);
       pen.DeleteObject();
   pOldPen->DeleteObject();       
       pWnd->ReleaseDC(pDC);
}}MFC绘制数据静态内存

解决方案 »

  1.   

    if(i>160)
    {
    pData[i] =0;
    }
    数组总共160大小,不应该试图给160个以外的数据赋值。
    应该
    if(i>=160)
        break;
      

  2.   

    pDC->LineTo(i+1,pData[i+1]);这句有问题吧
      

  3.   

    for(i=0;i<(int)dwDrawLength-1;i++)
    你确定dwDrawLength的长度小于160?你的数组大小是160,所以干脆把dwDrawLength直接改成160
      

  4.   

    for(i=0;i<(unsigned short)dwDrawLength;i++)
     {
    if(i>=160)
    {
    pData[i] =0;
    continue;
    }pData[i] = biodata[i]/5000;
    pDC->MoveTo(i,pData[i]);
    pDC->LineTo(i+1,pData[i+1]);
     }
    for里的。dwDrawLength改为dwDrawLength-1