刚刚开始用VS2005,VB不太熟,从网上找的宏改了一下
将下面的代码粘贴到宏项目里面
使用前修改一下 Dim gAuthor As String = "" 和 Dim gCompany As String = ""
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports System.Diagnostics
Public Module DoxyComment
'全局变量: 作者和公司
Dim gAuthor As String = "ChenGuangXing"
Dim gCompany As String = "ChenGuangXing"
' Doxygen主页的标题
Sub DoxyMainPage()
Dim outTextDoc As TextDocument
Dim outText As EditPoint
DTE.ActiveDocument.Selection.GotoLine(1) '移动光标到第一行
outTextDoc = DTE.ActiveDocument.Object("TextDocument")
outText = outTextDoc.StartPoint.CreateEditPoint()
outText.Insert("/**" + vbCrLf)
outText.Insert(" * @mainpage Title of Main Page" + vbCrLf)
outText.Insert(" * " + vbCrLf)
outText.Insert(" * Descriptive information placed on main page." + vbCrLf)
outText.Insert(" * <p/> <br/> " + vbCrLf)
outText.Insert(" */" + vbCrLf)
DTE.ActiveDocument.Selection.GotoLine(2)
End Sub
' --------------------------------------------------
' 生成文件说明注释
' --------------------------------------------------
Sub DoxyFileHead()
Dim outTextDoc As TextDocument
Dim outText As EditPoint
DTE.ActiveDocument.Selection.GotoLine(1)
outTextDoc = DTE.ActiveDocument.Object("TextDocument")
outText = outTextDoc.StartPoint.CreateEditPoint()
outText.Insert("/*" + vbCrLf)
outText.Insert(" * Copyright(C) " + Date.Today.Year.ToString() + "," + gCompany + " 保留所有权利。( All rights reserved. )" + vbCrLf)
outText.Insert(" * " + vbCrLf)
outText.Insert(" * @file " + DTE.ActiveDocument.Name + vbCrLf)
outText.Insert(" * @brief 简要介绍" + vbCrLf)
outText.Insert(" * @details 详细描述." + vbCrLf)
outText.Insert(" * @author " + gAuthor + vbCrLf)
outText.Insert(" * @version 1.0" + vbCrLf)
outText.Insert(" * @date " + Date.Today.ToLongDateString() + vbCrLf)
outText.Insert(" * @todo " + vbCrLf)
outText.Insert(" * @see " + vbCrLf)
'outText.Insert(" * log: " + vbCrLf)
outText.Insert(" */" + vbCrLf)
DTE.ActiveDocument.Selection.GotoLine(10)
End Sub
' --------------------------------------------------
' 生成变量说明注释
' --------------------------------------------------
Sub DoxyVariable()
Dim preSpaceCount As Integer = 0 ' 注释前面的空格数, 缩进(单位:字符)
Dim outTextDoc As TextDocument
Dim outText As EditPoint
Dim iCurrentLineNumber As Integer
iCurrentLineNumber = DTE.ActiveDocument.Selection.CurrentLine '.ToString()
outTextDoc = DTE.ActiveDocument.Object("TextDocument")
outText = outTextDoc.StartPoint.CreateEditPoint()
' 移动文本输入点到指定行上
outText.MoveToLineAndOffset(iCurrentLineNumber, 1)
Dim strSpace As String = ""
Dim iSpaceIndex As Integer
For iSpaceIndex = 1 To preSpaceCount
strSpace = strSpace + " "
Next
outText.Insert(strSpace + "/** " + vbCrLf)
outText.Insert(strSpace + "* @brief 简要介绍" + vbCrLf)
outText.Insert(strSpace + "*/" + vbCrLf)
End Sub
' --------------------------------------------------
'
' 函数注释解析部分
'
' --------------------------------------------------
Public Structure ITEMDATA
Public itemType As Integer
Public itemText As String
End Structure
Public lItemList As New System.Collections.Generic.List(Of ITEMDATA)(4)
Private Function ParseFunctionDescription(ByVal funText As String) As Boolean
Dim strItem As String
Dim idata As ITEMDATA
Dim strSplit As String() = funText.Split("(")
If strSplit.Length = 1 Then
Return False
End If
'解析函数名称部分
If strSplit.Length > 2 Then
strItem = strSplit(strSplit.Length - 2).Trim()
Else
strItem = strSplit(0).Trim()
End If
Dim strHeadSplit As String() = strItem.Split(" ")
strItem = strHeadSplit(strHeadSplit.Length - 1).Trim()
idata.itemType = 1
idata.itemText = strItem.Trim()
lItemList.Add(idata)
'解析参数部分
strItem = strSplit(strSplit.Length - 1).Trim()
If strItem.Substring(0, 1) <> ")" Then
Dim iend As Integer = strItem.IndexOf(")", 0)
Dim strParams As String = strItem.Substring(0, iend).Trim()
Dim strParamSplit As String() = strParams.Split(",")
For Each strItem In strParamSplit
idata.itemType = 2
idata.itemText = strItem.Trim()
lItemList.Add(idata)
Next strItem
Else
idata.itemType = 2
idata.itemText = "无参数"
lItemList.Add(idata)
End If
'解析返回值类型
Dim iIndex As Integer
For iIndex = 0 To strHeadSplit.Length - 2
idata.itemType = 3
idata.itemText = strHeadSplit(iIndex).Trim()
lItemList.Add(idata)
Next iIndex
Return True
End Function
' --------------------------------------------------
'
' 根据函数声明生成注释
'
' --------------------------------------------------
Sub DoxyFunction()
Dim preSpaceCount As Integer = 0 ' 注释前面的空格数, 缩进(单位:字符)
Dim outTextDoc As TextDocument
Dim outText As EditPoint
Dim iCurrentLineNumber As Integer
Dim iLineLength As Integer
Dim strFunText As String
Dim iItemIndex As Integer
Dim idata As ITEMDATA
lItemList.Clear()
iCurrentLineNumber = DTE.ActiveDocument.Selection.CurrentLine.ToString()
outTextDoc = DTE.ActiveDocument.Object("TextDocument")
outText = outTextDoc.StartPoint.CreateEditPoint()
' 移动文本输入点到指定行上
outText.MoveToLineAndOffset(iCurrentLineNumber, 1)
iLineLength = outText.LineLength
strFunText = outText.GetText(iLineLength)
iLineLength = strFunText.Trim().Length
'但前行没有内容直接返回
If iLineLength = 0 Then
Return
End If
' 解析函数名称
Dim bResult As Boolean = ParseFunctionDescription(strFunText.Trim())
If bResult = False Then
lItemList.Clear()
Return
End If
Dim pcount As Integer = 0
Dim rcount As Integer = 0
Dim strSpace As String = ""
Dim iSpaceIndex As Integer
For iSpaceIndex = 1 To preSpaceCount
strSpace = strSpace + " "
Next
outText.Insert(strSpace + "/** " + vbCrLf)
For iItemIndex = 0 To lItemList.Count - 1
idata = lItemList.Item(iItemIndex)
Select Case idata.itemType
Case 1
outText.Insert(strSpace + "* @brief 简短描述" + vbCrLf)
outText.Insert(strSpace + "* " + vbCrLf) ' + idata.itemText + vbCrLf) ’函数名称
outText.Insert(strSpace + "* @details 详细描述" + vbCrLf)
outText.Insert(strSpace + "* " + vbCrLf)
Case 2
If idata.itemText <> "无参数" Then
outText.Insert(strSpace + "* @param " + idata.itemText + vbCrLf)
pcount = pcount + 1
End If
Case 3
If rcount = 0 Then
outText.Insert(strSpace + "* @return " + idata.itemText + vbCrLf)
outText.Insert(strSpace + "* @retval status The program status. " + vbCrLf)
outText.Insert(strSpace + "* <ul> " + vbCrLf)
outText.Insert(strSpace + "* <li> 0 = Failure " + vbCrLf)
outText.Insert(strSpace + "* <li> 1 = Success " + vbCrLf)
outText.Insert(strSpace + "* </ul> " + vbCrLf)
outText.Insert(strSpace + "*" + vbCrLf)
End If
rcount = rcount + 1
Case 4
Case 5
End Select
Next
outText.Insert(strSpace + "* @todo Make it do something. " + vbCrLf)
outText.Insert(strSpace + "* @bug To be Microsoft Certified, " + vbCrLf)
outText.Insert(strSpace + "* must never deallocate memory. " + vbCrLf)
outText.Insert(strSpace + "* @exception StringIndexOutOfRangeException " + vbCrLf) '+ Date.Today.ToLongDateString() 日期
outText.Insert(strSpace + "* if index is not between " + vbCrLf)
outText.Insert(strSpace + "* <code>0</code> and " + vbCrLf)
outText.Insert(strSpace + "* <code>length() - 1</code>." + vbCrLf)
outText.Insert(strSpace + "* @see http://java.sun.com " + vbCrLf)
outText.Insert(strSpace + "*/" + vbCrLf)
lItemList.Clear() '清楚所有元素
End Sub
' --------------------------------------------------
' 生成函数语句说明注释
' --------------------------------------------------
Sub LineRemark()
Dim preSpaceCount As Integer = 0 ' 注释前面的空格数, 缩进(单位:字符)
Dim outTextDoc As TextDocument
Dim outText As EditPoint
Dim iCurrentLineNumber As Integer
iCurrentLineNumber = DTE.ActiveDocument.Selection.TopLine
outTextDoc = DTE.ActiveDocument.Object("TextDocument")
outText = outTextDoc.StartPoint.CreateEditPoint()
' 移动文本输入点到指定行上
outText.MoveToLineAndOffset(iCurrentLineNumber - 1, 1)
Dim strSpace As String = ""
Dim iSpaceIndex As Integer
For iSpaceIndex = 1 To preSpaceCount
strSpace = strSpace + " "
Next
outText.Insert(strSpace + "/****************************** " + " add by " + gAuthor + Date.Today.ToLongDateString() + " " + Date.Now.Hour.ToString + ":" + Date.Now.Minute.ToString + " *************************************/" + vbCrLf)
iCurrentLineNumber = DTE.ActiveDocument.Selection.BottomLine + 1
' 移动文本输入点到指定行上
outText.MoveToLineAndOffset(iCurrentLineNumber + 1, 1)
outText.Insert(strSpace + "/****************************** " + " add by " + gAuthor + Date.Today.ToLongDateString() + " " + Date.Now.Hour.ToString + ":" + Date.Now.Minute.ToString + " *************************************/" + vbCrLf)
End Sub
Sub DoxyClass()
Dim preSpaceCount As Integer = 0 ' 注释前面的空格数, 缩进(单位:字符)
Dim outTextDoc As TextDocument
Dim outText As EditPoint
Dim iCurrentLineNumber As Integer
iCurrentLineNumber = DTE.ActiveDocument.Selection.CurrentLine '.ToString()
outTextDoc = DTE.ActiveDocument.Object("TextDocument")
outText = outTextDoc.StartPoint.CreateEditPoint()
' 移动文本输入点到指定行上
outText.MoveToLineAndOffset(iCurrentLineNumber, 1)
Dim strSpace As String = ""
outText.Insert(strSpace + "/** " + vbCrLf)
outText.Insert(strSpace + "* @brief 简短描述" + vbCrLf)
outText.Insert(strSpace + "* " + vbCrLf)
outText.Insert(strSpace + "* @details 详细描述" + vbCrLf)
outText.Insert(strSpace + "* " + vbCrLf)
outText.Insert(strSpace + "* @note This class has no class. " + vbCrLf)
outText.Insert(strSpace + "* @attention Should only be used by those who " + vbCrLf)
outText.Insert(strSpace + "* know what they are doing. " + vbCrLf)
outText.Insert(strSpace + "* @warning Not certified for use within mission " + vbCrLf)
outText.Insert(strSpace + "* critical or life sustaining systems." + vbCrLf)
outText.Insert(strSpace + "* @author " + gAuthor + vbCrLf)
outText.Insert(strSpace + "* @date " + Date.Today.ToLongDateString() + vbCrLf)
outText.Insert(strSpace + "* @version 0.2.0.1 (alpha)" + vbCrLf)
outText.Insert(strSpace + "* Note the following example code: " + vbCrLf)
outText.Insert(strSpace + "* @code " + vbCrLf)
outText.Insert(strSpace + "* Window win = new Window(parent); " + vbCrLf)
outText.Insert(strSpace + "* win.show(); " + vbCrLf)
outText.Insert(strSpace + "* @endcode" + vbCrLf)
outText.Insert(strSpace + "* @bug Division by zero does not work. " + vbCrLf)
outText.Insert(strSpace + "* @todo Finish writing the class." + vbCrLf)
outText.Insert(strSpace + "*/ " + vbCrLf)
End Sub
End Module
// 这是Doxygen注释的效果
MainPage,最后显示在Doxygen主页上的标题
/**
* @mainpage Title of Main Page
*
* Descriptive information placed on main page.
* <p/> <br/>
*/
FileHead
/**
* @file NewClass.java
*
* @brief A brief file description.
* @details More verbose file description.
* @author ChenGuangXing
* @version 1.0
* @date 2013年12月4日
* @todo
* @see NewClass
*/
Member Data
/**
* @brief Short member data description.
*/
int dataMember;
Class
/**
* @brief Short class description.
*
* @details Verbose description of class details.
*
* @note This class has no class.
* @attention Should only be used by those who
* know what they are doing.
* @warning Not certified for use within mission
* critical or life sustaining systems.
* @author Fred McClurg, fred-mcclurg@uiowa.edu
* @date June 10, 2010
* @version 0.2.0.1 (alpha)
* Note the following example code:
* @code
* Window win = new Window(parent);
* win.show();
* @endcode
* @bug Division by zero does not work.
// @TODO Finish writing the class.
*/
class ClassName extends ExtendedClassName
{
/* do nothing */
}
MemberFunction
/**
* @brief Short method description.
*
* @details Verbose description of method
* (or function) details.
*
* @param args Command line argument.
*
* @return The status of the program.
*
* @retval status The program status.
* <ul>
* <li> 0 = Failure
* <li> 1 = Success
* </ul>
*
* @todo Make it do something.
*
* @bug To be Microsoft Certified,
* must never deallocate memory.
*
* @exception StringIndexOutOfRangeException
* if index is not between
* <code>0</code> and
* <code>length() - 1</code>.
*
* @see NewClass
* @see http://java.sun.com
*/
public static int main(String[] args)
{
...
return( status );
}
哪位有更好的方法记得分享一下
提问! 为毛我的vs2005双击了宏之后什么效果都没有?
回答: 因为你没装
vs2005的sp1