VC下使用Macro (vbs)来实现标准函数注释的自动添加

  今天看代码,看到一些代码没有函数注释,突然想到可以用宏来实现注释的自动添加,还添加了按钮,颇有成就感,故总结一下,积累经验。   Vc下面可以直接录制宏(Tools->Record quick Macros),这样可以把鼠标,键盘动作录制下来,录制以后可以编辑,(Tools->Macro,选中宏名称,点 EDIT 就可以进入宏文件中进行编辑)。默认的存储文件名是 MYMACRO.DSM,也可以直接打开编辑.   编辑代码是用vbs 写的,代码如下:

'------------------------------------------------------------------------------
'FILE DESCRIPTION: New Macro File
'------------------------------------------------------------------------------

Sub FunctionHead()
'DESCRIPTION: 函数注释 标准格式
'Begin Recording
ActiveDocument.Selection.NewLine
 ActiveDocument.Selection = "//"
 ActiveDocument.Selection = "/*"
 for i=0 to 100
     ActiveDocument.Selection = "="
 next
 ActiveDocument.Selection.NewLine

 ActiveDocument.Selection = "//函数名:"
 ActiveDocument.Selection.NewLine
 ActiveDocument.Selection = "//作者:"
 ActiveDocument.Selection.NewLine
 ActiveDocument.Selection = "//日期:"
 ActiveDocument.Selection = Date 
 ActiveDocument.Selection = "  "
 ActiveDocument.Selection = Time
 ActiveDocument.Selection.NewLine
 ActiveDocument.Selection = "//功能:"
 ActiveDocument.Selection.NewLine
 ActiveDocument.Selection = "//输入参数:"
 ActiveDocument.Selection.NewLine
 ActiveDocument.Selection = "//返回值:"
 ActiveDocument.Selection.NewLine
 ActiveDocument.Selection = "//修改记录:"
 ActiveDocument.Selection.NewLine
 ActiveDocument.Selection = "//备注:"
ActiveDocument.Selection.NewLine
 ActiveDocument.Selection = "//"
 for i=0 to 100
     ActiveDocument.Selection = "="
 next
  ActiveDocument.Selection = "*/" 
ActiveDocument.Selection.NewLine
'End Recording
End Sub


Sub FileHead()
'DESCRIPTION: 文件注释 标准格式
'Begin Recording
 ActiveDocument.Selection.NewLine
 ActiveDocument.Selection = "//"
 ActiveDocument.Selection = "/*"
 for i=0 to 100
     ActiveDocument.Selection = "="
 next
 ActiveDocument.Selection.NewLine
 ActiveDocument.Selection = "//文件名:"
 ActiveDocument.Selection.NewLine
 ActiveDocument.Selection = "//作者:"
 ActiveDocument.Selection.NewLine
 ActiveDocument.Selection = "//日期:"
 ActiveDocument.Selection = Date   
 ActiveDocument.Selection = "  "
 ActiveDocument.Selection = Time
 ActiveDocument.Selection.NewLine
 ActiveDocument.Selection = "//功能:"
 ActiveDocument.Selection.NewLine
' ActiveDocument.Selection = "//输入参数:"
 'ActiveDocument.Selection.NewLine
' ActiveDocument.Selection = "//返回值:"
' ActiveDocument.Selection.NewLine
 ActiveDocument.Selection = "//修改记录:"
 ActiveDocument.Selection.NewLine
 ActiveDocument.Selection = "//备注:"
 ActiveDocument.Selection.NewLine
 ActiveDocument.Selection = "//"
 for i=0 to 100
     ActiveDocument.Selection = "="
 next
  ActiveDocument.Selection = "*/" 
  ActiveDocument.Selection.NewLine
'End Recording
End Sub

   在写完宏后,可以选择 Tools->Macro->Option ->Toolbats,把新制作的宏做成按钮显示,然后选择一个配套的icon,就可以在需要时直接加入注释了,很方便的哦,如果不够你还可以添加快捷键完全使用键盘操作。。。。。。。。。。。。

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值