在.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)