(C++)如何在VC++6.0中添加批量注释和取消批量注释的功能

VC++6.0开发环境虽然有丰富的功能,但是没有提供批量注释和取消批量注释的功能。
这里,我们用VBScript脚本来添加这个功能。
 
1.首先打开VC++6.0,选择File/New,然后选择要新建的文件类型。
 



 
2.点击确定后,填写相应的描述。

 


 
3.然后输入代码,点击保存后,关闭VC++6.0。


 
这样就在文件夹中生成了一个 .dsm 文件。


 
4. 打开一个C++工程,按照图片中的操作选择 工具——>定制 。


 
5. 选择  附加项和宏文件,选择刚才制作的文件node.dsm。


 
6. 勾上node。


 
7.  选择  命令, 在 类别 中选择  Macros  。




 
8.  将 鼠标 按住 SetSelNote ,将其拖到工具栏中,会弹出下面的对话框。


 
9. CancelSelNote的做法与SetSelNote一样。
 
10.  最后在工具栏中,就出现了你自己定义的批量注释和消除批量注释的图标了。


 
=====================================================================================================
文中的代码:
'------------------------------------------------------------------------------
'FILE DESCRIPTION: 为开发环境添加批量注释或取消注释
'------------------------------------------------------------------------------

Sub SetSelNote()'Sun DESCRIPTION: 过程SetSelNote 用于将选中的文本转换为注释
 dim CurWin '当前获得的窗口
 set CurWin = ActiveWindow
 if CurWin.type<>"Text" Then '判断当前窗口是否是文本窗口
  MsgBox "当前窗口不是代码窗口"
 else
  NoteType = "//"
   BeginLine = ActiveDocument.Selection.TopLine
   EndLine   = ActiveDocument.Selection.BottomLine
  if EndLine < BeginLine then
   Line = BeginLine
   BeginLine = EndLine
   EndLine = Line
  else
   for  row = BeginLine To EndLine
     ActiveDocument.Selection.GoToLine row
     ActiveDocument.Selection.SelectLine'选中当前行
     ActiveDocument.Selection = NoteType + ActiveDocument.Selection
   Next
  End if
 End if
End Sub
Sub CancelSelNote()
 dim CurWin '当前获得的窗口
 set CurWin = ActiveWindow
 if CurWin.type<>"Text" Then '判断当前窗口是否是文本窗口
     MsgBox "当前窗口不是代码窗口"
 else
   BeginLine = ActiveDocument.Selection.TopLine
   EndLine   = ActiveDocument.Selection.BottomLine
  if EndLine < BeginLine then
   Line = BeginLine
   BeginLine = EndLine
   EndLine = Line
  else
   for  row = BeginLine To EndLine
     ActiveDocument.Selection.GoToLine row
     ActiveDocument.Selection.SelectLine'选中当前行
     SelBlock = ActiveDocument.Selection
     Trim(SelBlock)
     pos = instr(SelBlock,"//")
     if pos <>0 then
       RightBlock = Right(SelBlock, Len(SelBlock)-2)
       ActiveDocument.Selection = RightBlock
     End if
   Next
  End if
 End if
End Sub

来自 <http://blog.163.com/fantasy_sunny/blog/static/195918212201222504855353/>


猜你喜欢

转载自www.cnblogs.com/qiulidong/p/11736982.html