1、利用工具中自带的按钮实现:

Tools-->Customize-->Add-ins and Macro Files-->将SAMPLE项选中-->Commands-->Category中选择Macros-->在Commands中将CommentOut拖到工具栏,再选中一个Images,点击OK即可。

这种方法是使用/*  */进行多行注释的,而且不能全部一次取消,使用起来并不方便。

2、利用VBA 宏实现:

Tools-->Macro-->输入Macro Name-->Edit-->Description-->点击OK,删除刚才生成的代码,贴代码:
'多行注释
Sub Comment()
 if Documents.Count = 0 then
  exit sub
 end if 
     lTopLine = ActiveDocument.Selection.TopLine
 lBottomLine = ActiveDocument.Selection.BottomLine
 lInsertPoint = ActiveDocument.Selection.CurrentLine
For I = lTopLine To lBottomLine
  ActiveDocument.Selection.MoveTo I, 1
  ActiveDocument.Selection.SelectLine
  s = ActiveDocument.Selection.Text
  if s <> vbCrLf then
   s = "//" + vbTab + s
  end if
  ActiveDocument.Selection.Text = s
 Next
if lTopLine = lInsertPoint then
  ActiveDocument.Selection.MoveTo lBottomLine, dsEndOfLine
  ActiveDocument.Selection.MoveTo lTopLine, 1, dsExtend
 else
  ActiveDocument.Selection.MoveTo lTopLine, 1
  ActiveDocument.Selection.MoveTo lBottomLine, dsEndOfLine, dsExtend
 end if

End Sub
'多行反注释
Sub Uncomment()
 if Documents.Count = 0 then
  exit sub
 end if

lTopLine = ActiveDocument.Selection.TopLine
 lBottomLine =ActiveDocument.Selection.BottomLine
 lInsertPoint = ActiveDocument.Selection.CurrentLine
For I = lTopLine To lBottomLine
  ActiveDocument.Selection.MoveTo I, 1
  ActiveDocument.Selection.SelectLine
  s = ActiveDocument.Selection.Text
  while left(s, 1) = " " OR left(s, 1) = vbTab
   s = right(s, len(s) - 1)
  Wend
if left(s, 3) = "//" + vbTab then
   s = right(s, len(s) - 3)
  elseif left(s, 2) = "//" then
   s = right(s, len(s) - 2)
  end if

ActiveDocument.Selection.Text = s
 Next
if lTopLine = lInsertPoint then
  ActiveDocument.Selection.MoveTo lBottomLine, dsEndOfLine
  ActiveDocument.Selection.MoveTo lTopLine, 1, dsExtend
 else
  ActiveDocument.Selection.MoveTo lTopLine, 1
  ActiveDocument.Selection.MoveTo lBottomLine, dsEndOfLine, dsExtend
 end if

ActiveDocument.Selection.SmartFormat
End Sub
关闭并保存。
Tools-->Customize-->Commands-->在Category中选择Marcos-->在右侧Commands中拖出刚才生成的两个宏名到工具条上,-->分别选择Images图标。
设置快捷键:Keyboard-->Category中选择Macros,在Commands中选择一个然后设置快捷键即可。

3、转自:http://blog.csdn.net/jiaolongdy/archive/2010/12/30/6106782.aspx

取消/注释的宏,可以用于C++,java,VB
VC内使用方法:
将文件格式更改为dsm,放置于Program Files/Microsoft Visual Studio/COMMON/MSDev98/Macros目录下
打开VC——Customize——add-ins and Macro files
勾选上Comment,然后选择键盘,类别里选择Macros,CustomCommentOut设置好快捷键就可以了

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

4、转自:http://hi.baidu.com/starloooooove/blog/item/9324343ba0364ee014cecb2a.html

打开记事本,输入如下代码:

Sub CommentBlock()
With ActiveDocument.Selection
'对于当前窗口打开的文档中选中的文本
    .ReplaceText "%", "//", dsMatchRegExpB
'在开始位置增加 // 注释
End With
End Sub

Sub UncommentBlock()
With ActiveDocument.Selection
   .ReplaceText "%//", "", dsMatchRegExpB
   '同样的,去掉在选择文本中开头找到的注释符号
End With
End Sub

安装使用这个宏文件:

1、把这个文件命名为COMMENTMAC.dsm,保存到你的VS安装目录下的O:/VS6/Common/MSDev98/Macros中;

2、在VS6的工具条上按下右键,点击Customize下

1)、ADD-INS and Macro Files属性页,选择COMMENTMAC”;

2)、选择keyboard属性页,category下选Macros,为Commands选择快捷键

vc6中进行多行注释和反注释的方法相关推荐

  1. VC6中使用高版本系统API的方法

    有同学在如鹏论坛提问,在VC6中使用GetListBoxInfo这个API函数的时候编译提示: 'GetListBoxInfo' : undeclared identifier 详见:http://s ...

  2. IDEA中如何设置文件头注释和方法注释(详解)

    文件头注释和方法注释的两种方式 方法一: 文件头注释: 打开File–>Settings–>Editor–>File and Code Templates–>includes– ...

  3. Source Insight 4.0 快捷键设置多行注释与反注释

    步骤一:Options--->Key Assignments,如下图 步骤二:在Command:中输入Edit:comment,会过滤后出现Edit:Comment Lines和Edit:Un- ...

  4. Source Insight 4.0设置注释与反注释的快捷键

    之前有一篇详细的说明Source Insight 4.0:source insight教程:常用设置.快捷键.附带source insight3.5和4的对比 source insight查看函数调用 ...

  5. IDEA中多行注释及取消注释的快捷键分享

    这篇文章主要介绍了IDEA中多行注释及取消注释的快捷键分享,具有很好的参考价值,希望对大家有所帮助.一起跟随小编过来看看吧 1.一次性添加多行注释的快捷键 首先选中要注释区域,然后 ctrl+/ 这个 ...

  6. 关于eclipse的注释和反注释的快捷键

    使用eclipse那么久了额,对注释和反注释的快捷键一直很模糊,现在记下来,方便查看. 注释和反注释有两种方式.如对下面这段代码片段(①)进行注释: private String value; pri ...

  7. vim编辑器---批量注释与反注释

    在使用vim编写代码的时候,经常需要用到批量注释与反注释一段代码.下面简要介绍其操作. 方法一 块选择模式 插入注释: 用v进入virtual模式 用上下键选中需要注释的行数 按Control+v(w ...

  8. 我们如何在Python中创建多行注释?

    When we need to comment on multiple lines/statements, there are two ways to do this, either comment ...

  9. dev多行注释_Python代码注释的用法和意义

    01. 注释的作用 在大多数编程语言中,注释都是一项很有用的功能.在一些简单的程序中只包含Python代码,但随着程序越来越大.越来越复杂,就应在其中添加说明,对你解决问题的方法进行大致的阐述.注释让 ...

最新文章

  1. 安卓java代码标签_Android实现动态添加标签及其点击事件
  2. 安卓 通过intent调用系统文件管理器打开指定路径目录
  3. android wps表格如何设置边框颜色
  4. linux java获取文件创建时间_Linux查看文件的最初创建时间
  5. hadoop应用开发技术..._Hadoop
  6. mysql 注释写法有哪些_mysql的注释有几种写法?
  7. C++ STL vector详解
  8. java restlet 教程_Restlet 2.0 边学边写(五)Restlet的POST、PUT和DELETE
  9. pptx文件怎么打开(ppt兼容包下载)
  10. 遇到from playsound import playsoundModuleNotFoundError: No module named ‘playsound‘解决办法
  11. 公司办公提高无线网络质量解决方案
  12. FTP网络服务器 Xlight+FlashFXP
  13. Windows Server 2008 R2 WSUS服务器的详细配置和部署
  14. 利用WireShark分析H264码流
  15. epub电子书如何用Windows电脑打开?
  16. ZeroC Ice 暂记
  17. 【工具使用系列】TeX宏包之绘图宏包pgf/tikz
  18. OpenCV打开相机
  19. Mac系统 Terminal终端功能使用方法
  20. html图片滚动红点_HTML+CSS入门 CSS头像右上角的红点

热门文章

  1. 一、Focal Loss理论及代码实现
  2. Qt识别输入文件后缀
  3. Udacity机器人软件工程师课程笔记(一)-样本搜索和找回-基于漫游者号模拟器
  4. 在Ubuntu 14.04.5 64bit上安装git GUI客户端GitKraken
  5. 使用sigaction处理内核信号
  6. early EOF fatal: index-pack failed
  7. 学术-数学:哥德巴赫猜想
  8. Java Exception
  9. [UE4]死亡后调整视角
  10. (转)使用 Spring缓存抽象 支持 EhCache 和 Redis 混合部署