看了younker的Comment/Uncomment selected code in Visual C++ 一文后,深有收获。
.NET/develop/read_article.ASP?id=578">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++文件试试,是不是很爽?
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10752043/viewspace-990187/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/10752043/viewspace-990187/