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

来源:互联网 发布:网络文学创作原理pdf 编辑:程序博客网 时间:2024/05/15 06:27

C++6.0开发环境虽然有丰富的功能,但是没有提供批量注释和取消批量注释的功能。

这里,我们用VBScript脚本来添加这个功能。

 

1.首先打开VC++6.0,选择File/New,然后选择要新建的文件类型。

 2012年03月25日 - fantasy - 悠然见南山

 

2.点击确定后,填写相应的描述。
2012年03月25日 - fantasy - 悠然见南山
 
 
3.然后输入代码,点击保存后,关闭VC++6.0。
2012年03月25日 - fantasy - 悠然见南山
 
这样就在文件夹中生成了一个 .dsm 文件。
2012年03月25日 - fantasy - 悠然见南山
 

4. 打开一个C++工程,按照图片中的操作选择 工具——>定制 。
2012年03月25日 - fantasy - 悠然见南山
 
5. 选择  附加项和宏文件,选择刚才制作的文件node.dsm。
2012年03月25日 - fantasy - 悠然见南山
 
6. 勾上node。
2012年03月25日 - fantasy - 悠然见南山
 
7.  选择  命令, 在 类别 中选择  Macros  。
2012年03月25日 - fantasy - 悠然见南山


2012年03月25日 - fantasy - 悠然见南山
 
8.  将 鼠标 按住 SetSelNote ,将其拖到工具栏中,会弹出下面的对话框。
2012年03月25日 - fantasy - 悠然见南山
 
9. CancelSelNote的做法与SetSelNote一样。
 
10.  最后在工具栏中,就出现了你自己定义的批量注释和消除批量注释的图标了。
2012年03月25日 - fantasy - 悠然见南山
 
=====================================================================================================
文中的代码:

'------------------------------------------------------------------------------
'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

原创粉丝点击