您的位置:首页 > 编程语言 > C语言/C++

给VC++6.0加快捷注释和取消注释

2015-11-24 16:22 323 查看
首先在根目录下找到你的vc++6.0,我的是在c盘的一个叫MSDev98的文件夹里,打开文件夹后,在Macros文件夹中有下面的文件:



找到之后,先新建一个文本框,并命名为comment.dsm,最开始的时候,我直接把程序粘贴到文本框里,保存后,发现是txt的格式,然后想在属性里改格式,但是没能成功。之后百度过很多转换格式的,包括暴风影音也可以在文件下的工具里转换dsm文件。最后是在无意间看到一个问题的回答,终于解决了问题。
在记事本里面把txt转换成其他格式的方法:另存为的时候,选择保存类型为所有文件,然后在文件名中输入文件名,并输入你要的格式的后缀,比如我输入的是commend.dsm(其实应该是comment


在记事本里面输入以下程序,
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 = "//" ' 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 If End Sub 成功后的文件应该是这样的:

之后打开vc++6.0, 工具->定制->附加项和宏文件,选择commend如下:(英文版的类似)

再选择命令,在下拉选项中选择Macros,出现如下的,拖动CustomCommentOut放置在工具栏里


拖动后出现如下界面,选择自己喜欢的方式即可:

出现的效果如下:

这样就大功告成啦

我觉得在这个过程中,网络的资源特别重要,不懂得多在网上查找,多看一些资料和回答,让我对一个我不清楚的问题认识的更清楚,印象也更深刻。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息