注释与反注释Comment/Uncomment selected code in Visual C++

王朝vc·作者佚名  2006-01-08
宽屏版  字体: |||超大  

看了younker的Comment/Uncomment selected code in Visual C++ 一文后,深有收获。

http://www.csdn.net/develop/read_article.asp?id=578

我照着文章上的描述做了一个Add-ins,但是toolbar总是只有一个button。uncomment的button不出现,调了一会儿,未成功。后来,我想用宏的方式将younker的代码扒下来。结果居然很容易的就成功了。而且,代码简单方便(有更简单的,告诉我 :-) )。代码如下:

Sub linecomment()

lTopLine = ActiveDocument.Selection.TopLine

lBottomLine =ActiveDocument.Selection.BottomLine

For I = lTopLine To lBottomLine

ActiveDocument.Selection.MoveTo I, 1

ActiveDocument.Selection.SelectLine

s = ActiveDocument.Selection.Text

s = "//" + s

ActiveDocument.Selection.Text = s

Next

End Sub

Sub lineuncomment()

lTopLine = ActiveDocument.Selection.TopLine

lBottomLine =ActiveDocument.Selection.BottomLine

For I = lTopLine To lBottomLine

ActiveDocument.Selection.MoveTo I, 1

ActiveDocument.Selection.SelectLine

s = ActiveDocument.Selection.Text

if left(s,2) = "//" then

s = right(s, len(s) - 2)

end if

ActiveDocument.Selection.Text = s

Next

End Sub

有兴趣的兄弟可以这样做:

1。点击tool->macros...菜单,点击edit进入编辑界面,将上面的两个vbscript子程序paste上去,关闭此窗口。

2。点击tool->customize菜单,选择command标签,在下拉框中选择macros,在右边的commands列表中,按住左键直接拖动linecomment到工具条上去,根据提示选择图片或文字注释,lineuncomment同理。

3。大功告成。打开一个c/c++文件试试,是不是很爽?

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
© 2005- 王朝网络 版权所有