龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > 软件开发 > VC开发 >

实现类似VC中可设断点的编辑窗口[图](2)

时间:2009-12-30 15:42来源:未知 作者:admin 点击:
分享到:
4、 添加一个用于描画左边显示条的函数 PaintLeft() { CBrush brushb(RGB(245,245,230)); int m_breakpoint; CDC* hdc; hdc = GetWindowDC(); CRect rect; GetClientRect(rect); hdc-FillRect (CRe
  4、 添加一个用于描画左边显示条的函数

PaintLeft()
{
   CBrush brushb(RGB(245,245,230));
   int m_breakpoint;
   CDC* hdc;
   hdc = GetWindowDC();
   CRect rect;
   GetClientRect(&rect);
   hdc->FillRect (CRect(rect.left+2 ,rect.top+2 ,rect.left + m_LineHeight + 7,rect.Height ()+2),&brushb);//画底色
   brushb.DeleteObject ();
   CEdit& theEdit = GetEditCtrl ();
   int nFirstVisible = theEdit.GetFirstVisibleLine();  //得到当前显示的最上端的行号
   CBrush OrigBrush,brushf(RGB(255,0,0));
   CBrush *oldBrush = (CBrush*)hdc->SelectObject (brushf);
   OrigBrush.FromHandle((HBRUSH)oldBrush);
   IntList::iterator it;
   for(it = lBreakPoint.begin(); it != lBreakPoint.end(); it++)
   {
     m_breakpoint = *it;
     if(m_breakpoint > nFirstVisible)
     {
       int point = (m_breakpoint-1 - nFirstVisible)*m_LineHeight +3;  //计算断点位置
      
       if(point < (rect.bottom - m_LineHeight+1))
       {
         hdc->Ellipse(rect.left + 5, point, rect.left+ m_LineHeight + 4,point+m_LineHeight);//画断点
       }
     }
   }
   hdc->SelectObject (&OrigBrush);
   OrigBrush.DeleteObject();
   brushf.DeleteObject ();
}
  5、 处理鼠标左键单击,添加删除断点。本文发表于http://bianceng.cn(编程入门网)

if(point.x < m_LineHeight+6)
{
     point.x += 20;
     CEdit& theEdit = GetEditCtrl ();
     int n = theEdit.CharFromPos(point);
     AddRemoveBP(HIWORD(n)+1);
}
  6、 再加一个热键处理得到当前光标所在的行。

CEdit& theEdit = GetEditCtrl ();
int newpoint = theEdit.LineFromChar (-1) + 1;
AddRemoveBP(newpoint);
  7、 在一些必要的消息处理后面调用PaintLeft。OK!大功告成!!(^%$#@#@$#$$%……呵呵,俺想起小宝…………)

精彩图集

赞助商链接