需要环境:DOXYGEN, graphviz, HHW。。。配置环境GOOGLE上搜一下有很多很多,我这里给大家共享下我结合网上的一些再加上自己修改BUG和添加部分功能之后的注释宏:
PS:函数注释的时候如果函数头部超过一行时,则选中函数头部然后点“函数注释宏”,就可以了。。
直接上宏了:
'------------------------------------------------------------------------------
'FILE DESCRIPTION: 网上下载的宏,ROBIN做了部分修改,内含doxygen注释宏等。
'------------------------------------------------------------------------------
'辅助函数
'Strips the leading tab spaces.
Function YYStripTabs (ByVal MyStr)
Do While InStr(MyStr, vbTab) <> 0
MyStr = Right(MyStr, Len(MyStr) - InStr(MyStr, vbTab))
Loop
YYStripTabs = Trim(MyStr)
End Function
Sub ModuleBeginCommen()
'DESCRIPTION: 模块开始的批注部分
'Begin Recording
ActiveDocument.Selection.NewLine
ActiveDocument.Selection = "/** @defgroup"
ActiveDocument.Selection.NewLine
ActiveDocument.Selection = "* @{"
ActiveDocument.Selection.NewLine
ActiveDocument.Selection = "*/"
end Sub
Sub ModuleEndCommen()
'DESCRIPTION: 模块结束的批注部分
'Begin Recording
ActiveDocument.Selection.NewLine
ActiveDocument.Selection = "/** @}*/"
end Sub
Sub GroupBeginCommen()
'DESCRIPTION: 全局变量或宏所在的组注释开始
'Begin Recording
ActiveDocument.Selection.NewLine
ActiveDocument.Selection = "/** @name 全局变量或宏所在的组(例如:文件名常量)"
ActiveDocument.Selection.NewLine
ActiveDocument.Selection = "* @{"
ActiveDocument.Selection.NewLine
ActiveDocument.Selection = "*/"
end Sub
Sub GroupEndCommen()
'DESCRIPTION: 全局变量或宏所在的组注释结束
'Begin Recording
ActiveDocument.Selection.NewLine
ActiveDocument.Selection = "/** @}*/"
end Sub
Sub FileHeadCommen()
'DESCRIPTION: 文件注释 标准格式
'Begin Recording
ActiveDocument.Selection.NewLine
ActiveDocument.Selection = "/** "
ActiveDocument.Selection.NewLine
ActiveDocument.Selection = "* @author (C) Robin SWUST zhou_cs@qq.com"
ActiveDocument.Selection.NewLine
ActiveDocument.Selection = "* @version V1.0"
ActiveDocument.Selection.NewLine
ActiveDocument.Selection = "* @date "
ActiveDocument.Selection = Date
ActiveDocument.Selection = " "
ActiveDocument.Selection = Time
ActiveDocument.Selection.NewLine
ActiveDocument.Selection = "* @note descriptions"
ActiveDocument.Selection.NewLine
ActiveDocument.Selection = "*/"
End Sub
Sub ClassCommen()
'DESCRIPTION: 类声明注释 标准格式
'Begin Recording
ActiveDocument.Selection.NewLine
ActiveDocument.Selection = "/** "
ActiveDocument.Selection.NewLine
ActiveDocument.Selection = "* @class "
ActiveDocument.Selection.NewLine
ActiveDocument.Selection = "* @brief brief description "
ActiveDocument.Selection.NewLine
ActiveDocument.Selection = "* detailed description "
ActiveDocument.Selection.NewLine
ActiveDocument.Selection = "*/"
End Sub
'生成Doxygen样式的函数注释
Sub FunctionCommen()
'DESCRIPTION: AddDoxygenFunctionDescription
'DESCRIPTION: Creates a comment block for the currently selected C/C++ function prototype
'Throughout this file, ActiveDocument.Selection is used in place
'of ActiveDocument.Selection.Text. The two are equivalent, and can
'be used interchangeably. The reason for the equivalence is that
'Text is regarded as the default property to use. All uses of
'ActiveDocument.Selection without any other property default to the Text
'property.
'
if ActiveDocument.Language = dsCPP Then
Header = YYStripTabs(Trim(ActiveDocument.Selection))
'Get the function return type.
'RetTp 返回类型
'判断所选择的行
StartLine = ActiveDocument.Selection.TopLine
EndLine = ActiveDocument.Selection.BottomLine
If EndLine < StartLine Then
Temp = StartLine
StartLine = EndLine
EndLine = Temp
End If
'如果行数大于1,则将各行的字符串合成一个字符串
tmpLine = StartLine
do while tmpLine <= EndLine
ActiveDocument.Selection.GoToLine tmpLine
ActiveDocument.Selection.SelectLine
Header = Header & YYStripTabs(Trim(ActiveDocument.Selection))
tmpLine = tmpLine +1
loop
if Header <> "" then
Reti = InStr(Header, " ")
Loc = InStr(Header, "(")
if Reti < Loc Then
RetTp = Left(Header, Reti)
Header = Right(Header, Len(Header) - Reti)
End If
'Get the function name.
'fcName 函数名城
Loc = InStr(Header, "(") - 1
Loc2 = InStr(Header, ")")
if Loc > 0 And Loc2 > 0 then 'make sure there is a '(' and a ')'
fcName = Left(Header, Loc)
Header = Right(Header, Len(Header) - Len(fcName))
'Do we have storage type on the return type?
Trim (fcName)
Do While InStr(fcName," ") <> 0
retTp = retTp + Left(fcName,InStr (fcName," "))
fcName = Right(fcName, Len(fcName) - InStr(fcName," "))
loop
'Get the function parameters.
iPrm = 0
iPrmA = 0
prms = Header
'Count the number of parameters.
Do While InStr(prms, ",") <> 0
iPrm = iPrm + 1
prms = Right(prms, Len(prms) - InStr(prms, ","))
Loop
'Store the parameter list in the array.
If iPrm > 0 Then ' If multiple params.
iPrm = iPrm + 1
iPrmA = iPrm
Redim ParamArr(iPrm)
Do While InStr(header, ",") <> 0
ParamArr(iPrm) = Left(Header, InStr (Header, ",") - 1)
'Remove brace from first parameter.
If InStr(ParamArr(iPrm), " (") <> 0 Then
ParamArr(iPrm) = Right(ParamArr(iPrm), _
Len(ParamArr(iPrm))-InStr(ParamArr(iPrm)," ("))
Trim(ParamArr(iPrm))
End If
Header = Right(Header, Len(Header) - InStr(Header,","))
iPrm = iPrm - 1
Loop
ParamArr(iPrm) = Header
'Remove trailing brace from last parameter.
If InStr(ParamArr(iPrm), ")") <> 0 Then
ParamArr(iPrm) = Left(ParamArr(iPrm), _
InStr(ParamArr(iPrm), ")") - 1)
Trim(ParamArr(iPrm))
End If
Else 'Possibly one param.
Redim ParamArr(1)
Header = Right(Header, Len(Header) - 1) ' Strip the first brace.
Trim(Header)
ParamArr(1) = YYStripTabs(Header)
If InStr(ParamArr(1), ")") <> 1 Then
ParamArr(1) = Left(ParamArr(1), InStr(ParamArr(1), ")") - 1)
Trim(ParamArr(1))
iPrmA = 1
End If
End If
'Position the cursor one line above the selected text.
ActiveDocument.Selection.LineUp
ActiveDocument.Selection.LineDown
ActiveDocument.Selection.StartOfLine
ActiveDocument.Selection = vbLf
'声称Doxygen样注释文档
Descr = "/**" + _
vbLf + " * " + fcName + " : " + _
vbLf
'函数功能简要说明
Descr = Descr + _
+ " * @brief " + "PURPOSE" + _
vbLf
'Print the parameter list.
Last = iPrmA
Do While iPrmA <> 0
'Remove a line feed from any of the arguments.
If InStr(ParamArr(iPrmA), vbLf) <> 0 Then
ParamArr(iPrmA) = Right(ParamArr(iPrmA), _
(Len(ParamArr(iPrmA)) - _
InStr(ParamArr(iPrmA), vbLf)))
Trim(ParamArr(iPrmA))
End If
ParamArr(iPrmA) = YYStripTabs(ParamArr(iPrmA))
'If there are 2+ parameters, the first parameter will
'have a '(' prepended to it, remove it here:
if iPrmA = Last AND Last <> 1 then
ParamArr(iPrmA) = Right(ParamArr(iPrmA), _
Len(ParamArr(iPrmA)) - 1)
End If
Do While InStr(ParamArr(iPrmA)," ") <> 0
ParamArr(iPrmA) = Right(ParamArr(iPrmA), Len(ParamArr(iPrmA)) - InStr(ParamArr(iPrmA)," "))
loop
Descr = Descr + _
+ " * @param [IN]" + ParamArr(iPrmA) + _
vbLf
iPrmA = iPrmA - 1
Loop
'@param 参数名及其解释(我还习惯在param后加[IN]表示输入还是输出参数)
'@exception 用来说明异常类及抛出条件
'@return 对函数返回值做解释
'@note 表示注解,暴露给源码阅读者的文档
'@remark 表示评论,暴露给客户程序员的文档
'@since 表示从那个版本起开始有了这个函数
'@deprecated 引起不推荐使用的警告
'@see 表示交叉参考
'对函数自从哪个版本开始存在的说明来生成DOXYGEN注释
Descr = Descr + _
+ " * @since " + "Version 1.0(从那个版本起开始有了这个函数)" + _
vbLf
'对函数注解来生成DOXYGEN注释
Descr = Descr + _
+ " * @details " + "对函数的详细描述" + _
vbLf
'to see
Descr = Descr + _
+ " * @see " + "表示交叉参考" + _
vbLf
'对函数返回值来生成DOXYGEN注释
Descr = Descr + _
+ " * @return " + RetTp + _
vbLf
'对函数备注来生成DOXYGEN注释
Descr = Descr + _
+ " * @remark " + "表示评论、备注,暴露给客户程序员的文档" + _
vbLf + " */" + _
vbLf
ActiveDocument.Selection = Descr
Else
MsgBox("It is possible that the function you are trying to"+_
" work with has a syntax error.")
End if
End If
Else
MsgBox("You need to have an active C/C++ document open"+ _
vbLF+"with the function prototype selected.")
End If
End Sub
'生成doxygen样式的公开变量的注释
Sub ValCommen ()
if ActiveDocument.Language = dsCPP Then
ActiveDocument.Selection = ActiveDocument.Selection + _
vbTab + "/**< . . */"
End if
End Sub
'生成doxygen样式的一般通用的注释
Sub BriefLineCommen()
if ActiveDocument.Language = dsCPP Then
ActiveDocument.Selection = "/** @brief" + " */"
End if
End Sub
以上是VC6++的DOXYGEN注释宏
下面是VS2005下的DOXYGEN注释宏
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports System.Diagnostics
Public Module DoxygenComments
'------------------------------------------------------------------------------
'FILE DESCRIPTION: 网上下载的宏,ROBIN做了部分修改,内含doxygen注释宏等。
'------------------------------------------------------------------------------
'辅助函数
'Strips the leading tab spaces.
Function YYStripTabs(ByVal MyStr)
With DTE.ActiveDocument.Selection
Do While InStr(MyStr, vbTab) <> 0
MyStr = Right(MyStr, Len(MyStr) - InStr(MyStr, vbTab))
Loop
YYStripTabs = Trim(MyStr)
End With
End Function
Sub ModuleBeginCommen()
'DESCRIPTION: 模块开始的批注部分
'Begin Recording
With DTE.ActiveDocument.Selection
.NewLine()
.Text = "/** @defgroup"
.NewLine()
.Text = "* @{"
.NewLine()
.Text = "*/"
End With
End Sub
Sub ModuleEndCommen()
'DESCRIPTION: 模块结束的批注部分
'Begin Recording
With DTE.ActiveDocument.Selection
.NewLine()
.Text = "/** @}*/"
End With
End Sub
Sub GroupBeginCommen()
'DESCRIPTION: 全局变量或宏所在的组注释开始
'Begin Recording
With DTE.ActiveDocument.Selection
.NewLine()
.Text = "/** @name 全局变量或宏所在的组(例如:文件名常量)"
.NewLine()
.Text = "* @{"
.NewLine()
.Text = "*/"
End With
End Sub
Sub GroupEndCommen()
'DESCRIPTION: 全局变量或宏所在的组注释结束
'Begin Recording
With DTE.ActiveDocument.Selection
.NewLine()
.Text = "/** @}*/"
End With
End Sub
Sub FileHeadCommen()
'DESCRIPTION: 文件注释 标准格式
'Begin Recording
With DTE.ActiveDocument.Selection
.NewLine()
.Text = "/** "
.NewLine()
.Text = "* @author (C) Robin SWUST zhou_cs@qq.com"
.NewLine()
.Text = "* @version V1.0"
.NewLine()
.Text = "* @time "
.Text = System.DateTime.Now.ToString()
'.NewLine()
.Text = vbCrLf + "* @note descriptions"
.NewLine()
.Text = "*/"
End With
End Sub
Sub ClassCommen()
'DESCRIPTION: 类声明注释 标准格式
'Begin Recording
With DTE.ActiveDocument.Selection
.NewLine()
.Text = "/** "
.NewLine()
.Text = "* @class "
.NewLine()
.Text = "* @brief brief description "
.NewLine()
.Text = "* detailed description "
.NewLine()
.Text = "*/"
End With
End Sub
'生成Doxygen样式的函数注释
Sub FunctionCommen()
'DESCRIPTION: AddDoxygenFunctionDescription
'DESCRIPTION: Creates a comment block for the currently selected C/C++ function prototype
'Throughout this file, ActiveDocument.Selection is used in place
'of ActiveDocument.Selection.Text. The two are equivalent, and can
'be used interchangeably. The reason for the equivalence is that
'Text is regarded as the default property to use. All uses of
'ActiveDocument.Selection without any other property default to the Text
'property.
'
With DTE.ActiveDocument.Selection
Dim StartLine As Integer
Dim EndLine As Integer
Dim Temp As Integer
Dim tmpLine As Integer
Dim Reti As Integer
Dim Loc As Integer
Dim Loc2 As Integer
Dim fcName As String
Dim Header As String
Dim prms As String
Dim RetTp As String
If ActiveDocument.Language = EnvDTE.Constants.dsCPP Then
Header = YYStripTabs(Trim(.Text))
'Get the function return type.
'RetTp 返回类型
'判断所选择的行
StartLine = .TopLine
EndLine = .BottomLine
If EndLine < StartLine Then
Temp = StartLine
StartLine = EndLine
EndLine = Temp
End If
'如果行数大于1,则将各行的字符串合成一个字符串
tmpLine = StartLine
Do While tmpLine <= EndLine
.GoToLine(tmpLine)
.SelectLine()
Header = Header & YYStripTabs(Trim(.Text))
tmpLine = tmpLine + 1
Loop
If Header <> "" Then
Reti = InStr(Header, " ")
Loc = InStr(Header, "(")
If Reti < Loc Then
RetTp = Left(Header, Reti)
Header = Right(Header, Len(Header) - Reti)
End If
'Get the function name.
'fcName 函数名城
Loc = InStr(Header, "(") - 1
Loc2 = InStr(Header, ")")
If Loc > 0 And Loc2 > 0 Then 'make sure there is a '(' and a ')'
fcName = Left(Header, Loc)
Header = Right(Header, Len(Header) - Len(fcName))
'Do we have storage type on the return type?
Trim(fcName)
Do While InStr(fcName, " ") <> 0
RetTp = RetTp + Left(fcName, InStr(fcName, " "))
fcName = Right(fcName, Len(fcName) - InStr(fcName, " "))
Loop
'MsgBox("robin1")
'Get the function parameters.
Dim iPrm, iPrmA As Integer
Dim ParamArr
'Dim ParamArr As String
iPrm = 0
iPrmA = 0
prms = Header
'Count the number of parameters.
Do While InStr(prms, ",") <> 0
iPrm = iPrm + 1
prms = Right(prms, Len(prms) - InStr(prms, ","))
Loop
'MsgBox("robin2")
'Store the parameter list in the array.
If iPrm > 0 Then ' If multiple params.
iPrm = iPrm + 1
iPrmA = iPrm
ReDim ParamArr(iPrm)
Do While InStr(Header, ",") <> 0
ParamArr(iPrm) = Left(Header, InStr(Header, ",") - 1)
'Remove brace from first parameter.
If InStr(ParamArr(iPrm), " (") <> 0 Then
ParamArr(iPrm) = Right(ParamArr(iPrm), _
Len(ParamArr(iPrm)) - InStr(ParamArr(iPrm), " ("))
Trim(ParamArr(iPrm))
End If
Header = Right(Header, Len(Header) - InStr(Header, ","))
iPrm = iPrm - 1
Loop
'MsgBox(iPrm)
ParamArr(iPrm) = Header
'Remove trailing brace from last parameter.
If InStr(ParamArr(iPrm), ")") <> 0 Then
ParamArr(iPrm) = Left(ParamArr(iPrm), _
InStr(ParamArr(iPrm), ")") - 1)
Trim(ParamArr(iPrm))
End If
'MsgBox("robin4")
Else 'Possibly one param.
ReDim ParamArr(1)
Header = Right(Header, Len(Header) - 1) ' Strip the first brace.
Trim(Header)
ParamArr(1) = YYStripTabs(Header)
If InStr(ParamArr(1), ")") <> 1 Then
ParamArr(1) = Left(ParamArr(1), InStr(ParamArr(1), ")") - 1)
Trim(ParamArr(1))
iPrmA = 1
End If
'MsgBox("robin5")
End If
'Position the cursor one line above the selected text.
'MsgBox("robin5-1")
.LineUp()
.LineDown()
.StartOfLine()
.Text = vbLf
'MsgBox("robin5-2")
'声称Doxygen样注释文档
Dim Descr As String
Descr = "/**" + vbCrLf + "*" + fcName + " : " + vbCrLf
'MsgBox(Descr)
'函数功能简要说明
Descr = Descr + vbCrLf + "* @brief " + "PURPOSE" + vbCrLf
'MsgBox(Descr)
'Print the parameter list.
Dim Last As Integer
Last = iPrmA
'MsgBox("robin6")
Do While iPrmA <> 0
'Remove a line feed from any of the arguments.
If InStr(ParamArr(iPrmA), vbLf) <> 0 Then
ParamArr(iPrmA) = Right(ParamArr(iPrmA), _
(Len(ParamArr(iPrmA)) - _
InStr(ParamArr(iPrmA), vbCrLf)))
Trim(ParamArr(iPrmA))
'MsgBox("robin7")
End If
ParamArr(iPrmA) = YYStripTabs(ParamArr(iPrmA))
'If there are 2+ parameters, the first parameter will
'have a '(' prepended to it, remove it here:
If iPrmA = Last And Last <> 1 Then
ParamArr(iPrmA) = Right(ParamArr(iPrmA), _
Len(ParamArr(iPrmA)) - 1)
'MsgBox("robin8")
End If
Do While InStr(ParamArr(iPrmA), " ") <> 0
ParamArr(iPrmA) = Right(ParamArr(iPrmA), Len(ParamArr(iPrmA)) - InStr(ParamArr(iPrmA), " "))
Loop
'MsgBox("robin9")
Descr = Descr + _
vbCrLf + "* @param [IN]" + ParamArr(iPrmA) + _
vbCrLf
iPrmA = iPrmA - 1
'MsgBox("robin10")
Loop
'@param 参数名及其解释(我还习惯在param后加[IN]表示输入还是输出参数)
'@exception 用来说明异常类及抛出条件
'@return 对函数返回值做解释
'@note 表示注解,暴露给源码阅读者的文档
'@remark 表示评论,暴露给客户程序员的文档
'@since 表示从那个版本起开始有了这个函数
'@deprecated 引起不推荐使用的警告
'@see 表示交叉参考
'对函数自从哪个版本开始存在的说明来生成DOXYGEN注释
Descr = Descr + _
vbCrLf + "* @since " + "Version 1.0(从那个版本起开始有了这个函数)" + _
vbCrLf
'MsgBox("robin11")
'对函数注解来生成DOXYGEN注释
Descr = Descr + _
vbCrLf + "* @details " + "对函数的详细描述" + _
vbCrLf
'MsgBox("robin12")
'to see
Descr = Descr + _
vbCrLf + "* @see " + "表示交叉参考" + _
vbCrLf
'MsgBox("robin13")
'对函数返回值来生成DOXYGEN注释
Descr = Descr + _
vbCrLf + "* @return " + RetTp + _
vbCrLf
' MsgBox("robin14")
'对函数备注来生成DOXYGEN注释
Descr = Descr + _
vbCrLf + "* @remark " + "表示评论、备注,暴露给客户程序员的文档" + _
vbCrLf + "*/" + _
vbCrLf
' MsgBox("robin15")
.Text = Descr
Else
MsgBox("It is possible that the function you are trying to" + _
vbCrLf + " work with has a syntax error.")
End If
End If
Else
MsgBox("You need to have an active C/C++ document open" + _
vbCrLf + "with the function prototype selected.")
End If
End With
End Sub
'生成doxygen样式的公开变量的注释
Sub ValCommen()
With DTE.ActiveDocument.Selection
If ActiveDocument.Language = EnvDTE.Constants.dsCPP Then
.Text = .Text + _
vbTab + "/**< . . */"
End If
End With
End Sub
'生成doxygen样式的一般通用的注释
Sub BriefLineCommen()
With DTE.ActiveDocument.Selection
If ActiveDocument.Language = EnvDTE.Constants.dsCPP Then
.Text = "/** @brief" + " */"
End If
End With
End Sub
End Module
VS2003下的注释宏只需要把VS2005中的 “Imports EnvDTE80”删除就可以了。