在.net环境下,按下三个/// 就可以自动添加函数注释,包括函数名、参数列表、返回值等信息。
在C++环境下通过MACRO宏也可以实现这个功能,宏代码如下:
Option Strict Off
Option Explicit Off
Imports EnvDTE
Imports System.Diagnostics
Public Module Comment
Sub FILE()
DTE.ActiveDocument.Selection.Text = "/******************************************************************************"
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Indent()
DTE.ActiveDocument.Selection.Text = "文件名称 : " + DTE.ActiveDocument.Name.ToString()
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "作 者 : "
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "创建时间 : " + System.DateTime.Now.ToLocalTime()
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "文件描述 :"
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "版权声明 : Copyright(C) 2008-2012"
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "修改历史 : N/A"
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.DeleteLeft()
DTE.ActiveDocument.Selection.Text = "*******************************************************************************/"
End Sub
Sub FUN()
Dim projectItem As ProjectItem = DTE.ActiveDocument.ProjectItem
Dim fileCodeMode As FileCodeModel = projectItem.FileCodeModel
Dim selectItem As TextSelection = DTE.ActiveDocument.Selection '当前选定内容
Dim point As TextPoint = selectItem.ActivePoint '读取当前位置
Dim codeElement As CodeElement = fileCodeMode.CodeElementFromPoint(point, vsCMElement.vsCMElementFunction)
Dim nCount As Integer = 0
If (codeElement Is Nothing) Then
Return '若不是函数名,直接返回
Else
DTE.ActiveDocument.Selection.MoveToPoint(codeElement.StartPoint)
DTE.ActiveDocument.Selection.Text = "/******************************************************************************"
nCount = codeElement.Children.Count '参数数目
End If
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.DeleteWhitespace()
DTE.ActiveDocument.Selection.Text = "描述 : "
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.Text = "参数 : "
For i = 1 To nCount
DTE.ActiveDocument.Selection.Indent()
DTE.ActiveDocument.Selection.Text = codeElement.Children.Item(i).Name
DTE.ActiveDocument.Selection.Text = (" --- 说明")
If (i <> nCount) Then
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.DeleteWhitespace()
DTE.ActiveDocument.Selection.Indent(1)
End If
Next
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.DeleteWhitespace()
DTE.ActiveDocument.Selection.Text = "返回 : "
DTE.ActiveDocument.Selection.NewLine()
DTE.ActiveDocument.Selection.DeleteWhitespace()
DTE.ActiveDocument.Selection.Text = "*******************************************************************************/"
DTE.ActiveDocument.Selection.NewLine()
End Sub
End Module
使用效果如下:
/******************************************************************************
描述 :
参数 : filename --- 说明
data --- 说明
dataSize --- 说明
返回 :
*******************************************************************************/
bool ReadTGA(const char *filename, byte* data, int dataSize)