在Qt Creator,eclipse等編輯器中,都默認有注釋代碼的快捷鍵:Ctrl + /。
注釋快捷鍵在程序編程當中的作用相當明顯,提高了編程效率。我在網(wǎng)上找到了一個在VC++6.0工具中添加注釋快捷鍵的方法,VC++6.0是以VB為腳本來配置的。
首先,找到VC++6.0的安裝路徑,假設在:D:\Program Files (x86)\Microsoft Visual Studio 6.0,那么進入到Common\MSDev98\Macros目錄下,全路徑為:D:\Program Files (x86)\Microsoft Visual Studio 6.0\Common\MSDev98\Macros。
在該目錄新建一個文本文件,并重命名為:comment.dsm,并打開增加以下內(nèi)容:
Sub CustomCommentOut()'DESCRIPTION: 注釋/取消注釋宏,可處理VB和C++、Java注釋 Dim win set win = ActiveWindow If win.type <> "Text" Then MsgBox "This macro can only be run when a text editor window is active." Else TypeOfFile = 3 If TypeOfFile > 0 And TypeOfFile < 6 Then If TypeOfFile > 3 Then CommentType = "'" ' VB注釋 CommentWidth = 1 Else CommentType = "http://" ' C++、java 注釋 CommentWidth = 2 End If StartLine = ActiveDocument.Selection.TopLine EndLine = ActiveDocument.Selection.BottomLine If EndLine < StartLine Then Temp = StartLine StartLine = EndLine EndLine = Temp End If ' 單行 If EndLine = StartLine Then ActiveDocument.Selection.StartOfLine dsFirstColumn ActiveDocument.Selection.CharRight dsExtend, CommentWidth If ActiveDocument.Selection = CommentType Then ActiveDocument.Selection.Delete Else ActiveDocument.Selection.StartOfLine dsFirstText ActiveDocument.Selection.CharRight dsExtend, CommentWidth If ActiveDocument.Selection = CommentType Then ActiveDocument.Selection.CharRight dsExtend ActiveDocument.Selection.Delete Else ActiveDocument.Selection.StartOfLine dsFirstText ActiveDocument.Selection = CommentType + vbTab + _ ActiveDocument.Selection End If End If ' 多行 Else For i = StartLine To EndLine ActiveDocument.Selection.GoToLine i CommentLoc = dsFirstColumn ActiveDocument.Selection.StartOfLine CommentLoc ActiveDocument.Selection.CharRight dsExtend, CommentWidth If ActiveDocument.Selection = CommentType Then ActiveDocument.Selection.Delete Else ActiveDocument.Selection.StartOfLine CommentLoc ActiveDocument.Selection = CommentType + _ ActiveDocument.Selection End If Next End If Else MsgBox("Unable to comment out the highlighted text" + vbLf + _ "because the file type was unrecognized." + vbLf + _ "If the file has not yet been saved, " + vbLf + _ "please save it and try again.") End If End IfEnd Sub
此時打開VC++6.0窗口,以下步驟:
1.打開菜單欄"Tools" -> "Customize" 打開了"Customize"對話框。
2.
3.
4.在代碼中,只需要選中代碼或者在光標所在行,執(zhí)行快捷鍵"Ctrl + /",進行注釋或取消注釋。
聯(lián)系客服