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

来源:互联网 发布:欧珀莱柔护防晒知乎 编辑:程序博客网 时间:2024/05/01 23:24

看了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++文件试试,是不是很爽?

原创粉丝点击