当前位置: 首页 > 图文教程 > 开发语言 > VC++ > 实现类似VC中可设断点的编辑窗口

VC++
宏的妙用
泛型编程与设计新思维
C++中的虚函数(一)
C++模板元编程
C++多态技术
通用结构复制函数
<C++实践系列>C++中的虚函数(virtual function)
<C++实践系列>C++中的引用(reference)
<C++实践系列>C++中的异常(exception)
<C++实践系列>C++中的模板(template)
构造函数中的this指针
串行化(Serialization)
二进制浏览、编辑的实现
介绍一个模板动态数组
VC++界面一揽子解决方案(第三版) 介绍
VC++通用GIS功能开发解决方案 2.0v 介绍
确定有穷自动机分析内核
委托、信号和消息反馈的模板实现技术
按照类型名称动态创建对象
Boost中应用的泛型编程技术

VC++ 中的 实现类似VC中可设断点的编辑窗口


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-30   浏览: 76 ::
收藏到网摘: n/a

实现类似VC中可设断点的编辑窗口
作者: cuick

下载本文示例源代码

运行效果图如下:



想做一个跟踪调试工具,于是到网上找类似VC可设置断点的EditView,可惜没找到(呵呵,俺E文不好,没去国外站点找)。那就自己做一个吧!!
唉!!为了这个小东西俺可是走了不少弯路!!
还好,今天终于做好了,拿出来与大家分享。

1、 创建一个工程………………俺不多说了,记住要选CeditView.
2、 在OnInitialUpdate()中设置EDIT的Margin,当然留出的空间用来画断点或行号等。并得到行高。

SIZE size;GetTextExtentPoint(GetDC()->GetSafeHdc (),"A",1,&size);m_LineHeight = size.cy;	//得到行的高度CEdit& theEdit = GetEditCtrl ();theEdit.SetMargins (m_LineHeight+6,0);	//设置编辑框的左边界theEdit.SetLimitText(10 * 1024);	//设置输入的最大文本
3、 保存断点的行号我用STL的list。
AddRemoveBP(int point){	IntList::iterator it;	it = find(lBreakPoint.begin (), lBreakPoint.end (), point);	if( it != lBreakPoint.end () )	//如果此行为设置了断点的行则删除否则添加	lBreakPoint.erase (it);	else	lBreakPoint.push_back (point);}
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、 处理鼠标左键单击,添加删除断点。
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!大功告成!!(^%$#@#@$#$$%……呵呵,俺想起小宝…………)