新书推介:《语义网技术体系》
作者:瞿裕忠,胡伟,程龚
   XML论坛     W3CHINA.ORG讨论区     计算机科学论坛     SOAChina论坛     Blog     开放翻译计划     新浪微博  
 
  • 首页
  • 登录
  • 注册
  • 软件下载
  • 资料下载
  • 核心成员
  • 帮助
  •   Add to Google

    >> 本版讨论高级C/C++编程、代码重构(Refactoring)、极限编程(XP)、泛型编程等话题
    [返回] 计算机科学论坛计算机技术与应用『 C/C++编程思想 』 → 用VC++编写象任务管理器中的CPU使用记录的波形显示的程序- - 查看新帖用户列表

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 3362 个阅读者浏览上一篇主题  刷新本主题   树形显示贴子 浏览下一篇主题
     * 贴子主题: 用VC++编写象任务管理器中的CPU使用记录的波形显示的程序- - 举报  打印  推荐  IE收藏夹 
       本主题类别:     
     卷积内核 帅哥哟,离线,有人找我吗?
      
      
      威望:8
      头衔:总统
      等级:博士二年级(版主)
      文章:3942
      积分:27590
      门派:XML.ORG.CN
      注册:2004/7/21

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给卷积内核发送一个短消息 把卷积内核加入好友 查看卷积内核的个人资料 搜索卷积内核在『 C/C++编程思想 』的所有贴子 访问卷积内核的主页 引用回复这个贴子 回复这个贴子 查看卷积内核的博客楼主
    发贴心情 用VC++编写象任务管理器中的CPU使用记录的波形显示的程序- -


                                           


    可以在OnTimer()中写下面代码:

    CDC* pDC;
    pDC = m_parentWnd->GetDC();  //m_parentWnd 为需要画波形图的Dialog的m_hWnd

    CSize szFont;

    szFont = pDC->GetTextExtent("1");

    CRect rcClient;
    m_parentWnd->GetClientRect(rcClient);  //得到画图的客户区域

    CDC dcMem;
    dcMem.CreateCompatibleDC(NULL);//这里我们就在内存中虚拟建造了DC

    CBitmap bitmap;
    CBitmap* pOldBitmap;
    if(bitmap.CreateCompatibleBitmap(pDC,rcClient.Width(), rcClient.Height()))//创建一与pDC兼容的位图,大小为整个客户区
    {
      pOldBitmap=dcMem.SelectObject(&bitmap);//将位图选入内存环境
      dcMem.SelectClipRgn(NULL);//使dc的整个客户区都成无效区
      dcMem.IntersectClipRect(rcClient);//再“与上”检取的无效区,使内存环境与pDC检取的无效区相等
    }

    CDC* pdcClient;
    CPen pen,pen1;
    // pdc = m_parentWnd->GetDC();
    pdcClient = &dcMem;
    CRect roundrc;

    BOOL bCanDrawline;
    bCanDrawline = IsCanDrawLine();

    //重新刷新背景
    if( bCanDrawline )
    {
      pdcClient->Rectangle(rcClient);
      CBrush bsh(RGB(0,0,0));
      pdcClient->FillRect(rcClient, &bsh);
    }

    // DrawGrids( pdcClient );

    int lineStartPos, lineEndPos;

    //画上下界限线, 把界面分成4等份
    POINT startPos,EndPos;
    int UpLimit, DownLimit, line_height;

    lineStartPos = rcClient.left;
    lineEndPos = rcClient.right;

    startPos.x = rcClient.left;
    startPos.y = rcClient.top + (rcClient.bottom-rcClient.top)*2/4;
    m_ZeroY = startPos.y;

    int imodvalue;
    imodvalue = m_lineheight % ( 2 * BETWEENSPACEVALUE );
    if( imodvalue != 0 ) m_lineheight -= imodvalue;

    UpLimit = m_ZeroY - m_lineheight;

    DownLimit = m_ZeroY + m_lineheight;

    line_height = m_lineheight;

    EndPos.x = rcClient.right;

    startPos.y = UpLimit;
    EndPos.y = UpLimit;

    pen1.CreatePen(PS_SOLID,1,RGB(0,128,0));
    CPen* pOldPen1 = (CPen*)pdcClient->SelectObject(&pen1);

    DrawGrids( pdcClient );

    pdcClient->SelectObject( pOldPen1 );

    pen1.DeleteObject();
    pen1.CreatePen(PS_SOLID,1,RGB(255,255,0));
    pOldPen1 = (CPen*)pdcClient->SelectObject(&pen1);

    int fnWidth, fnHeight;

    CString strup;
    if( m_MaxShow.GetLength()<1 )
      strup.Format("%.2f",linelimitevalue.UpLimiteValue);
    else  strup = m_MaxShow;
    CRect rcUpvalue;
    fnWidth = szFont.cx * strup.GetLength();
    fnHeight = szFont.cy;
    rcUpvalue.left = rcClient.right - fnWidth - 2;
    rcUpvalue.top = UpLimit - fnHeight - 2;
    rcUpvalue.bottom = rcUpvalue.top + fnHeight + 1;
    rcUpvalue.right = rcClient.right - 1;

    //写上界值
    pdcClient->SetBkMode(TRANSPARENT);

    pdcClient->SetTextColor(RGB(255,255,0));
    pdcClient->DrawText( strup, rcUpvalue, DT_CENTER);

    //画上界限
    pdcClient->MoveTo(startPos);
    pdcClient->LineTo(EndPos);

    //写零坐标值
    // CString strzero;
    // strzero.Format("%.2f",linelimitevalue.ZeroValue);
    // CRect rcZerovalue;

    // fnWidth = szFont.cx * strup.GetLength();
    // fnHeight = szFont.cy;

    // rcZerovalue.left = rcClient.right - fnWidth - 2;
    // rcZerovalue.top = m_ZeroY - fnHeight - 2;
    // rcZerovalue.right = rcClient.right - 1;
    // rcZerovalue.bottom = rcZerovalue.top + fnHeight + 1;

    // pdcClient->DrawText( strzero, rcZerovalue, DT_CENTER);

    //画零坐标线
    startPos.y = m_ZeroY;
    EndPos.y = m_ZeroY;
    pdcClient->MoveTo(startPos);
    pdcClient->LineTo(EndPos);

    //写下界值
    CString strDown;
    if( m_MinShow.GetLength()<1 )
      strDown.Format("%.2f",linelimitevalue.DownLimiteValue);
    else strDown = m_MinShow;
    CRect rcDownvalue;

    fnWidth = szFont.cx * strDown.GetLength();
    fnHeight = szFont.cy;

    rcDownvalue.left = rcClient.right - fnWidth - 2;
    rcDownvalue.top = DownLimit + 1;
    rcDownvalue.right = rcClient.right - 1;
    rcDownvalue.bottom = rcDownvalue.top + fnHeight + 2;

    pdcClient->DrawText( strDown, rcDownvalue, DT_CENTER);
    //画下界限
    startPos.y = DownLimit;
    EndPos.y = DownLimit;
    pdcClient->MoveTo(startPos);
    pdcClient->LineTo(EndPos);

    pdcClient->SelectObject(pOldPen1);

    pen.CreatePen(PS_SOLID,1,RGB(68,232,219));
    CPen* pOldPen = (CPen*)pdcClient->SelectObject(&pen);

    int i = 0;
    double *pdblPos;

    int iArrCount = m_arrYHeight.GetSize();

    if( (lineEndPos-lineStartPos)>(m_betweenspace*iArrCount) )
    {
      i = 0;
      m_fromPos.x = lineEndPos-m_betweenspace*iArrCount;
    }
    else
    {
      i = iArrCount - ( (lineEndPos-lineStartPos)/m_betweenspace );
      m_fromPos.x = lineStartPos;
    }

    if(m_arrYHeight.GetSize()<1) return FALSE;
    double dblpos;
    //画第一个点
    pdblPos = (double*)m_arrYHeight.GetAt(i);

    dblpos = *pdblPos;
    if(*pdblPos>99000) dblpos = 0;
    dblpos = (dblpos-linelimitevalue.ZeroValue)*m_ZoomInRatio;
    m_fromPos.y = m_ZeroY-int(dblpos/m_Height*line_height);

    if( *pdblPos<99000 )  //不是临时加的点
    {
      if( ( m_fromPos.y>=UpLimit )&&
       ( m_fromPos.y<=DownLimit )  )
      {
       pdcClient->SetPixel(m_fromPos,RGB(0,0,255));   //打蓝点
      }
      else
      {
       pdcClient->SetPixel(m_fromPos,RGB(255,0,0));   //打红点
      }
    }

    i++;

    double *pdblprePos;
    COLORREF clNaturaldot, clAlarmdot;
    clAlarmdot = RGB(255,0,0);
    clNaturaldot = RGB(255,255,255);

    while( (i<iArrCount) )
    {
      m_toPos.x = m_fromPos.x+m_betweenspace;
      pdblprePos = (double*)m_arrYHeight.GetAt(i-1);
      pdblPos = (double*)m_arrYHeight.GetAt(i);
      dblpos = *pdblPos;
      if(*pdblPos>90000) dblpos = 0;
      dblpos = (dblpos-linelimitevalue.ZeroValue)*m_ZoomInRatio;
      m_toPos.y = m_ZeroY-int(dblpos/m_Height*line_height);

    //  if( ( *pdblprePos>9000 )&&( *pdblPos>9000 ) )
      if( *pdblPos>9000 )
      {
       //不处理
      }
      else
      {
       pdcClient->MoveTo(m_fromPos);
       pdcClient->LineTo(m_toPos);

       if( ( m_fromPos.y>=UpLimit )&&
        ( m_fromPos.y<=DownLimit )  )
       {
        if( m_fromPos.y<m_ZeroY )
         pdcClient->SetPixel(m_fromPos.x,m_fromPos.y-1,clNaturaldot);   //打白点
        else
        {
         if( m_fromPos.y==m_ZeroY )
          pdcClient->SetPixel(m_fromPos.x,m_fromPos.y,clNaturaldot);   //打白点
         else pdcClient->SetPixel(m_fromPos.x,m_fromPos.y+1,clNaturaldot);   //打白点
        }
       }
       else
       {
        if( m_fromPos.y < UpLimit )
         pdcClient->SetPixel(m_fromPos.x,m_fromPos.y-1, clAlarmdot);   //打红点
        else pdcClient->SetPixel(m_fromPos.x,m_fromPos.y+1, clAlarmdot);   //打红点
       }


       if( ( m_toPos.y>=UpLimit )&&
        ( m_toPos.y<=DownLimit )  )
       {
        if( m_toPos.y < m_ZeroY )
         pdcClient->SetPixel(m_toPos.x,m_toPos.y-1,clNaturaldot);   //打白点
        else
        {
         if( m_toPos.y == m_ZeroY )
          pdcClient->SetPixel(m_toPos.x,m_toPos.y,clNaturaldot);   //打白点
         else pdcClient->SetPixel(m_toPos.x,m_toPos.y+1,clNaturaldot);   //打白点
        }
       }
       else
       {
        if( m_toPos.y < UpLimit )
         pdcClient->SetPixel(m_toPos.x,m_toPos.y-1,clAlarmdot);   //打红点
        else pdcClient->SetPixel(m_toPos.x,m_toPos.y+1,clAlarmdot);   //打红点
       }
      }

      m_fromPos = m_toPos;
      ++i;
    }

    pDC->BitBlt(rcClient.left,rcClient.top,rcClient.Width(),rcClient.Height(),&dcMem,0,0,SRCCOPY);//第一次拷贝到屏幕
    m_parentWnd->ReleaseDC(pDC);

    pdcClient->SelectObject(pOldPen);
    pdcClient->SelectObject(pOldBitmap);

    pdcClient->DeleteDC();
    pdcClient = NULL;


       收藏   分享  
    顶(0)
      




    ----------------------------------------------
    事业是国家的,荣誉是单位的,成绩是领导的,工资是老婆的,财产是孩子的,错误是自己的。

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2006/9/2 15:46:00
     
     GoogleAdSense
      
      
      等级:大一新生
      文章:1
      积分:50
      门派:无门无派
      院校:未填写
      注册:2007-01-01
    给Google AdSense发送一个短消息 把Google AdSense加入好友 查看Google AdSense的个人资料 搜索Google AdSense在『 C/C++编程思想 』的所有贴子 访问Google AdSense的主页 引用回复这个贴子 回复这个贴子 查看Google AdSense的博客广告
    2024/11/23 1:02:15

    本主题贴数1,分页: [1]

    管理选项修改tag | 锁定 | 解锁 | 提升 | 删除 | 移动 | 固顶 | 总固顶 | 奖励 | 惩罚 | 发布公告
    W3C Contributing Supporter! W 3 C h i n a ( since 2003 ) 旗 下 站 点
    苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
    77.881ms