VC下用宏来实现函数注释的自动添加

来源:互联网 发布:淘宝教程 华为网盘 编辑:程序博客网 时间:2024/05/20 03:44
  今天看代码,看到一些代码没有函数注释,突然想到可以用宏来实现注释的自动添加,还添加了按钮,颇有成就感,故总结一下,积累经验。   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 = "//"
 for i=0 to 100
     ActiveDocument.Selection = "="
 next
  ActiveDocument.Selection = "*/"  
  ActiveDocument.Selection.NewLine
'End Recording
End Sub


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


原文地址:http://blog.csdn.net/sangxiansheng/article/details/2487170

0 0