註釋與反註釋Comment/Uncomment selected code in Visual C++ (轉)

worldblog發表於2007-12-09
註釋與反註釋Comment/Uncomment selected code in Visual C++ (轉)[@more@]

看了younker的Comment/Uncomment ed code in Visual C++ 一文後,深有收穫。

/develop/read_article.?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進入編輯介面,將上面的兩個子paste上去,關閉此視窗。

2。點選tool->customize選單,選擇command標籤,在下拉框中選擇macros,在右邊的commands列表中,按住左鍵直接拖動linecomment到工具條上去,根據提示選擇圖片或文字註釋,lineuncomment同理。

3。大功告成。開啟一個c/c++試試,是不是很爽?


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10752043/viewspace-990187/,如需轉載,請註明出處,否則將追究法律責任。

相關文章