C语言网

 找回密码
 加入社区!

QQ登录

只需一步,快速开始

查看: 923|回复: 1

如何在vc6.0里面添加注释宏 [复制链接]

Rank: 1

主题
0
帖子
1
C币
2 枚
在线时间
0 小时
发表于 2010-8-26 11:25:04 |显示全部楼层
如何在vc6.0里面添加注释宏,请大侠写明白每一个步骤

Rank: 8Rank: 8

主题
24
帖子
636
C币
758 枚
在线时间
504 小时
发表于 2010-8-26 11:57:39 |显示全部楼层
帮你找的,仅供参考!看楼主你能用上不
VC6添加注释的宏 收藏
一、功能介绍

环境:VC 6.0

功能:在VC 6.0编辑器中为代码添加符合Doxygen标准的注释,其中包括:

1.         模块注释

2.         分组注释

3.         新头文件注释

4.         文件头注释

5.         简要注释

6.         详细注释

7.         类注释

8.         函数注释

9.         成员注释

10.     项目符号标记注释

此外还提供了以下两个功能:

1.         Comment out

2.         转移注释



二、安装

1.         将本文的VB宏保存到新建的文件COMMENT.DSM中,然后将ActiveDocument.Selection = "* Author: ***"中的“***”改为自己的名字,这个名字会出现在文件注释中。同样,将ActiveDocument.Selection = "* <pre><b>email: </b>mail@***</pre>"改为自己的邮箱地址。

2.         将COMMENT.DSM拷贝到VC6.0安装路径下的\Common\MSDev98\Macros目录中,这一步主要是为了加载宏方便。

3.         打开VC6.0开发环境,点击“Tools”à“Customize”,在弹出的对跨框中的“Add-ins and Macro Files”标签中选中复选框“COMMENT”(这个宏就是上一步中我们拷贝的宏,VC6.0会自动加载\Common\MSDev98\Macros目录中的宏)。

4.         点击“Command”标签,在Category的下拉列表中选择“Macros”,这时右边的“Command”列表会出现COMMENT.DSM中定义的12种注释功能。这12个功能分别对应的方法名如下:

a)         模块注释                            ModuleDescription

b)        分组注释                            GroupDescription

c)         新头文件注释                     NewFileDescription

d)        文件头注释                         FileDescription

e)         简要注释                            BriefDescription

f)         详细注释                            DetailDescription

g)        类注释                                ClassDescription

h)        函数注释                            FunctionDescription

i)          成员注释                            MemberDescription

j)          项目符号标记注释              ItemDescription

k)        Comment Out                      CustomCommentOut

l)          转移注释                            CommentLineToggle



其中转移注释举例如下:

Line 1: //This is a comment

Line 2: int a;

把鼠标放到第一行,点击转移注释按钮,代码变化如下:

Line 1: int a; //This is a comment

此时如果再次点击鼠标,,代码变化如下:

Line 1: //This is a comment

Line 2: int a;

此功能用来把注释从代码上方和代码末尾之间进行转移。

5.         把这12种注释功能分别放到VC6.0的工具栏中,或者指定快捷键,以便以后的操作。我们以“函数(方法)注释”为例进行操作。用鼠标点击“Command”中的“FunctionDescription”并拖放到VC6.0的工具栏中,此时会弹出一个标题为“Button Appearance”的对话框,用来选择刚才拖放到工具栏中的功能按钮的显示信息(例如是显示文字、图标,或者都显示),选择好之后点击“OK”,带有文字和(或)图标的可以实现“函数(方法)注释”功能的按钮便在工具栏中了。采用同样的方法把其他7个注释功能的按钮也放到工具栏中。

三、使用

在程序代码中需要插入注释的地方点击工具栏中相应的功能按钮可以插入注释。但是“函数(方法)注释”功能例外,在对函数(方法)进行注释时,需要选中函数的签名,例如选中int getMax(int a, int b)。

为了便于操作,可以为每个功能设定一个快捷键。以文件注释功能为例,在VC6.0的ToolsàCustomize的Keyboard中,Category选中Macros,然后找到FileDescription宏,鼠标点击“Press new shortcut”下面的文本框,按“Ctrl + 3”,鼠标点击“Assign”,这时快捷键设置成了Ctrl+3。

'/**   
'* @file COMMENT.DSM   
'* @brief VC6中添加文件头注释、类注释、函数注释、模块注释等。   
'* @author Hao Liming   
'* @date 2008-11-18 8:49:22   
'* @version 0.8   
'* <pre><b>copyright: </b></pre>   
'* <pre><b>email: </b>hao.limin@gmail.com</pre>   
'* <pre><b>company: </b>http://blog.csdn.net/donhao</pre>   
'* <pre><b>All rights reserved.</b></pre>   
'* <pre><b>modification:</b></pre>   
'* <pre>v0.8 对代码进行了优化</pre>   
'* <pre>v0.7 添加了新头文件注释</pre>   
'* <pre>v0.6 修改了文件头注释中@version的错误</pre>   
'* <pre>     修改了对inline函数生成注释时的错误</pre>   
'* <pre>     修改了对static函数生成注释时的错误</pre>   
'* <pre>     修改了将函数注释中返回为指针或引用例如为std::string &getName()时返回类型和函数名的错误</pre>   
'* <pre>     修改了将函数注释中形参为指针或引用例如为std::string &getName(int &age)时参数类型的错误</pre>   
'* <pre>v0.5 修改了文件注释内容与格式</pre>   
'* <pre>     添加了类描述;</pre>   
'* <pre>     修改了函数返回void以及函数参数为void时存在的问题</pre>   
'* <pre>v0.4 修正了不能为跨行函数签名插入注释的问题</pre>   
'* <pre>     修正了参数列表带有默认值的情况</pre>   
'* <pre>     修正了把virtual作为返回值的问题</pre>   
'* <pre>     修正了构造函数和析构函数注释的问题</pre>   
'* <pre>v0.3 添加了Comment Out、注释转移功能。这些功能由Adam Solesby[adam@solesby.com]实现</pre>   
'* <pre>v0.2 修正了文件注释中参数信息提取的错误</pre>   
'* <pre>     修正了插入注释时差入行的问题</pre>   
'* <pre>v0.1 基于http://blog.csdn.net/nicholasmax ... /08/14/1742223.aspx实现了函数注释、文件注释、简要注释、详细注释、模块注释、注释、公开变量注释、项目编号注释 </pre>   
'*/   
  
Function StripTabs(ByVal MyStr)   
    Do While InStr(MyStr, vbTab) <> 0   
        MyStr = Right(MyStr, Len(MyStr) - InStr(MyStr, vbTab))   
    Loop  
    StripTabs = Trim(MyStr)   
End Function  
'_________________________________________________________________   
'生成Doxygen样式的函数注释   
Sub FunctionDescription()   
    Dim win   
    set win = ActiveWindow   
    If win.type <> "Text" Then  
      MsgBox "This macro can only be run when a text editor window is active."  
    Else  
  
       '判断所选择的行   
        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 & StripTabs(Trim(ActiveDocument.Selection))   
            tmpLine = tmpLine +1   
        loop   
      
      '把回车换成空格   
        Header = replace(Header, vbcrlf, " ")   
      
        ActiveDocument.Selection.GoToLine StartLine   
      
        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  
  
            Loc = InStr(Header, "(") - 1   
            Loc2 = InStr(Header, ")")   
            if Loc > 0 And Loc2 > 0 then   
                fcName = Left(Header, Loc)   
                Header = Right(Header, Len(Header) - Len(fcName))   
   
                Trim(fcName)   
   
                '得到函数名称   
                Do While InStr(fcName, " ") <> 0   
                    retTp = retTp + Left(fcName, InStr(fcName, " "))   
                    fcName = Right(fcName, Len(fcName) - InStr(fcName, " "))   
                loop   
                  
                '如果函数名称第一个字符为"*"或"&",则做为返回值最后一个字符   
                if InStr(fcName, "*") =1 then   
                    retTp = Rtrim(retTp) + "*"  
                    fcName = Ltrim(Right(fcName, Len(fcName) - 1))   
                end if   
                if InStr(fcName, "&") =1 then   
                    retTp = Rtrim(retTp) + "&"  
                    fcName = Ltrim(Right(fcName, Len(fcName) - 1))   
                end if   
  
  
                '对返回值进行处理   
                '去掉virtual   
                if InStr(retTp, "virtual") <> 0 Then  
                    retTp = Ltrim(Right(retTp, Len(retTp) - Len("virtual")))   
                end if   
      
                '去掉inline   
                if InStr(retTp, "inline") <> 0 Then  
                    retTp = Ltrim(Right(retTp, Len(retTp) - Len("inline")))   
                end if   
  
                '去掉static   
                if InStr(retTp, "static") <> 0 Then  
                    retTp = Ltrim(Right(retTp, Len(retTp) - Len("static")))   
                end if   
                  
                iPrm = 0   
                iPrmA = 0   
                prms = Header   
  
                Do While InStr(prms, ",") <> 0   
                    iPrm = iPrm + 1   
                    prms = Right(prms, Len(prms) - InStr(prms, ","))   
                Loop  
                 
                If iPrm > 0 Then  
                    iPrm = iPrm + 1   
                    iPrmA = iPrm   
                    Redim ParamArr(iPrm)   
                    Do While InStr(header, ",") <> 0   
                        ParamArr(iPrm) = Left(Header, InStr(Header, ",") - 1)   
               
                        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   
        
                    If InStr(ParamArr(iPrm), ")") <> 0 Then  
                        ParamArr(iPrm) = Left(ParamArr(iPrm), InStr(ParamArr(iPrm), ")") - 1)   
                        Trim(ParamArr(iPrm))   
                    End If  
                Else  
                    Redim ParamArr(1)   
                    Header = Right(Header, Len(Header) - 1)   
                    Trim(Header)   
                    ParamArr(1) = StripTabs(Header)   
                    If InStr(ParamArr(1), ")") <> 1 Then  
                        ParamArr(1) = Left(ParamArr(1), InStr(ParamArr(1), ")") - 1)   
                        Trim(ParamArr(1))   
                        iPrmA = 1   
                        if ParamArr(1) = "void" then   
                          iPrmA = 0   
                        end if   
                    End If  
                End If  
   
  
                if ActiveDocument.Selection.CurrentLine <> 1 Then   
                    ActiveDocument.Selection.GoToLine ActiveDocument.Selection.CurrentLine - 1   
                    ActiveDocument.Selection.MoveTo ActiveDocument.Selection.CurrentLine, dsEndOfLine      
                    ActiveDocument.Selection.NewLine   
                end if   
  
                ActiveDocument.Selection = "/** "  
                ActiveDocument.Selection.NewLine   
  
               
                '判断是构造函数还是析构函数   
                if  len(Trim(RetTp)) > 0 Then  
                    ActiveDocument.Selection = "* @brief " + fcName +" "  
                else   
                    '为构造函数   
                    if Instr(fcName, "~") <> 0 then   
                        ActiveDocument.Selection = "* @brief " + "Destructor for " + Right(fcName, len(fcName)-1) +"."  
                    '为析构函数   
                    else   
                        ActiveDocument.Selection = "* @brief " + "Constructor for " + fcName +"."      
                    end if                        
                end if   
  
                ActiveDocument.Selection.NewLine   
                ActiveDocument.Selection = "* "  
                ActiveDocument.Selection.NewLine   
                ActiveDocument.Selection = "* Detailed description."  
  
  
                Last = iPrmA   
                Do While iPrmA <> 0   
                    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) = StripTabs(ParamArr(iPrmA))   
  
                    if iPrmA = Last AND Last <> 1 then   
                        ParamArr(iPrmA) = Right(ParamArr(iPrmA), Len(ParamArr(iPrmA)) - 1)   
                    End If  
                    ActiveDocument.Selection.NewLine   
                  
                    '首先判断参数列表中有没有'='号,如果有,则等号左边为参数名,右边为默认值。   
                    Dim defautValue   
                    If InStr(ParamArr(iPrmA), "=") <> 0 Then  
                        defautValue = Ltrim(Right(ParamArr(iPrmA), Len(ParamArr(iPrmA)) - InStr(ParamArr(iPrmA), "=")))   
                        ParamArr(iPrmA) = Rtrim(Left(ParamArr(iPrmA), InStr(ParamArr(iPrmA), "=") - 1))   
                    end if   
  
                    Do While InStr(defautValue, " ") <> 0   
                        defautValue = Right(defautValue, Len(defautValue) - InStr(defautValue, " "))   
                    loop   
  
                    Do While InStr(ParamArr(iPrmA), " ") <> 0   
                        ParamArr(iPrmA) = Right(ParamArr(iPrmA), Len(ParamArr(iPrmA)) - InStr(ParamArr(iPrmA), " "))   
                    loop   
  
                    '如果形参形如std::string &name时,应该将引用符号放到前边   
                    if InStr(ParamArr(iPrmA), "*") =1 OR InStr(ParamArr(iPrmA), "&") =1 then   
                        ParamArr(iPrmA) = Ltrim(Right(ParamArr(iPrmA), Len(ParamArr(iPrmA)) - 1))   
                    end if   
  
                    if Len(Trim(defautValue)) > 0 Then  
                        ActiveDocument.Selection = "* @param[in] " + LTrim(ParamArr(iPrmA)) +" Defaults to " + Trim(defautValue) + "."  
                    else   
                        ActiveDocument.Selection = "* @param[in] " + LTrim(ParamArr(iPrmA)) +" "  
                    end if   
                    iPrmA = iPrmA - 1   
                Loop  
   
                ActiveDocument.Selection.NewLine   
                if  len(Trim(RetTp)) > 0 And Trim(RetTp) <> "void" Then  
                    ActiveDocument.Selection = "* @return " + RetTp +" "  
                    ActiveDocument.Selection.NewLine               
                end if   
                ActiveDocument.Selection = "*/"  
            Else  
                MsgBox("It is possible that the function you are trying to"+_   
                        " work with has a syntax error.")   
            End if   
        End If  
    End if   
End Sub  
   
'_________________________________________________________________   
'生成doxygen样式的公开变量的注释   
Sub MemberDescription()   
    Dim win   
    set win = ActiveWindow   
    If win.type <> "Text" Then  
        MsgBox "This macro can only be run when a text editor window is active."  
    Else  
        ActiveDocument.Selection = ActiveDocument.Selection +" /**<  */"   
    End if   
End Sub  
   
'生成doxygen样式的一般通用的注释   
Sub DetailDescription()   
    Dim win   
    set win = ActiveWindow   
    If win.type <> "Text" Then  
        MsgBox "This macro can only be run when a text editor window is active."  
    Else  
        ActiveDocument.Selection.NewLine   
        ActiveDocument.Selection = "/** "  
        ActiveDocument.Selection.NewLine   
        ActiveDocument.Selection = "* @brief "  
        ActiveDocument.Selection.NewLine   
        ActiveDocument.Selection = "* "  
        ActiveDocument.Selection.NewLine   
        ActiveDocument.Selection = "* Detailed description."  
        ActiveDocument.Selection.NewLine   
        ActiveDocument.Selection = "*/"  
    end if   
End Sub  
  
'_________________________________________________________________   
'生成doxygen样式的简要注释   
Sub BriefDescription()   
    Dim win   
    set win = ActiveWindow   
    If win.type <> "Text" Then  
        MsgBox "This macro can only be run when a text editor window is active."  
    Else  
        ActiveDocument.Selection.NewLine   
        ActiveDocument.Selection = "/** @brief  */"  
    end if   
End Sub  
  
'_________________________________________________________________   
'生成doxygen样式的文件描述   
Sub FileDescription()   
    Dim win   
    set win = ActiveWindow   
    If win.type <> "Text" Then  
        MsgBox "This macro can only be run when a text editor window is active."  
    Else  
        if ActiveDocument.Selection.CurrentLine <> 1 Then   
            ActiveDocument.Selection.GoToLine ActiveDocument.Selection.CurrentLine - 1   
            ActiveDocument.Selection.MoveTo ActiveDocument.Selection.CurrentLine, dsEndOfLine      
            ActiveDocument.Selection.NewLine   
        end if   
        ActiveDocument.Selection = "/**"  
        ActiveDocument.Selection.NewLine   
        ActiveDocument.Selection = "* @file " + ActiveDocument.Name   
        ActiveDocument.Selection.NewLine   
        ActiveDocument.Selection = "* @brief "  
        ActiveDocument.Selection.NewLine   
        ActiveDocument.Selection = "* @author ***"  
        ActiveDocument.Selection.NewLine   
        ActiveDocument.Selection = "* @date "   
        ActiveDocument.Selection = DATE + TIME   
        ActiveDocument.Selection.NewLine   
        ActiveDocument.Selection = "* @version "  
        ActiveDocument.Selection.NewLine   
        ActiveDocument.Selection = "* <pre><b>copyright: </b></pre>"  
        ActiveDocument.Selection.NewLine   
        ActiveDocument.Selection = "* <pre><b>email: </b>***@***</pre>"  
        ActiveDocument.Selection.NewLine   
        ActiveDocument.Selection = "* <pre><b>company: </b>http://</pre>"  
        ActiveDocument.Selection.NewLine   
        ActiveDocument.Selection = "* <pre><b>All rights reserved.</b></pre>"  
        ActiveDocument.Selection.NewLine   
        ActiveDocument.Selection = "* <pre><b>modification:</b></pre>"  
        ActiveDocument.Selection.NewLine   
        ActiveDocument.Selection = "* <pre>Write modifications here.</pre>"  
        ActiveDocument.Selection.NewLine   
        ActiveDocument.Selection = "*/"  
    end if   
End Sub  
  
  
'_________________________________________________________________   
'生成doxygen样式的新文件描述   
Sub NewFileDescription()   
    Dim win   
    set win = ActiveWindow   
    If win.type <> "Text" Then  
        MsgBox "This macro can only be run when a text editor window is active."  
    Else  
        if ActiveDocument.Selection.CurrentLine <> 1 Then   
            ActiveDocument.Selection.GoToLine ActiveDocument.Selection.CurrentLine - 1   
            ActiveDocument.Selection.MoveTo ActiveDocument.Selection.CurrentLine, dsEndOfLine      
            ActiveDocument.Selection.NewLine   
        end if   
        ActiveDocument.Selection = "/**"  
        ActiveDocument.Selection.NewLine   
        ActiveDocument.Selection = "* @file " + ActiveDocument.Name   
        ActiveDocument.Selection.NewLine   
        ActiveDocument.Selection = "* @brief "  
        ActiveDocument.Selection.NewLine   
        ActiveDocument.Selection = "* @author ***"  
        ActiveDocument.Selection.NewLine   
        ActiveDocument.Selection = "* @date "   
        ActiveDocument.Selection = DATE + TIME   
        ActiveDocument.Selection.NewLine   
        ActiveDocument.Selection = "* @version "  
        ActiveDocument.Selection.NewLine   
        ActiveDocument.Selection = "* <pre><b>copyright: </b></pre>"  
        ActiveDocument.Selection.NewLine   
        ActiveDocument.Selection = "* <pre><b>email: </b>***@***</pre>"  
        ActiveDocument.Selection.NewLine   
        ActiveDocument.Selection = "* <pre><b>company: </b>http://</pre>"  
        ActiveDocument.Selection.NewLine   
        ActiveDocument.Selection = "* <pre><b>All rights reserved.</b></pre>"  
        ActiveDocument.Selection.NewLine   
        ActiveDocument.Selection = "* <pre><b>modification:</b></pre>"  
        ActiveDocument.Selection.NewLine   
        ActiveDocument.Selection = "* <pre>Write modifications here.</pre>"  
        ActiveDocument.Selection.NewLine   
        ActiveDocument.Selection = "*/"  
        if InStr(ActiveDocument.Name, ".") > 0 then   
            if Right(ActiveDocument.Name, Len(ActiveDocument.Name) - InStr(ActiveDocument.Name, ".")) = "h"  _   
            or Right(ActiveDocument.Name, Len(ActiveDocument.Name) - InStr(ActiveDocument.Name, ".")) = "hpp" _   
            or Right(ActiveDocument.Name, Len(ActiveDocument.Name) - InStr(ActiveDocument.Name, ".")) = "hh" then   
                def = "_" + UCase(Left(ActiveDocument.Name, InStr(ActiveDocument.Name, ".") - 1)_   
                + "_" + Right(ActiveDocument.Name, Len(ActiveDocument.Name) - InStr(ActiveDocument.Name, ".")))   
                ActiveDocument.Selection.NewLine   
                ActiveDocument.Selection = "#ifndef " + def   
                ActiveDocument.Selection.NewLine   
                ActiveDocument.Selection = "#define " + def   
                ActiveDocument.Selection.NewLine   
                ActiveDocument.Selection.NewLine   
                ActiveDocument.Selection = "#endif // "  + def   
                ActiveDocument.Selection.NewLine   
            end if   
        end if   
  
    end if   
End Sub  
'_________________________________________________________________   
'生成doxygen样式的项目编号描述   
Sub ItemDescription()   
    Dim win   
    set win = ActiveWindow   
    If win.type <> "Text" Then  
        MsgBox "This macro can only be run when a text editor window is active."  
    Else  
        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 = "* - "  
        ActiveDocument.Selection.NewLine   
        ActiveDocument.Selection = "* -# "  
        ActiveDocument.Selection.NewLine   
        ActiveDocument.Selection = "* -# "  
        ActiveDocument.Selection.NewLine   
        ActiveDocument.Selection = "*/"  
    end if   
End Sub  
  
'_________________________________________________________________   
'生成doxygen样式模块描述   
Sub ModuleDescription()   
    Dim win   
    set win = ActiveWindow   
    If win.type <> "Text" Then  
        MsgBox "This macro can only be run when a text editor window is active."  
    Else  
        ActiveDocument.Selection.NewLine   
        ActiveDocument.Selection = "/**"  
        ActiveDocument.Selection.NewLine   
        ActiveDocument.Selection = "* @defgroup "  
        ActiveDocument.Selection.NewLine   
        ActiveDocument.Selection = "* @brief "  
        ActiveDocument.Selection.NewLine   
        ActiveDocument.Selection = "* "  
        ActiveDocument.Selection.NewLine   
        ActiveDocument.Selection = "* Detailed description."  
        ActiveDocument.Selection.NewLine   
        ActiveDocument.Selection = "* @{"  
        ActiveDocument.Selection.NewLine   
        ActiveDocument.Selection = "*/"  
        ActiveDocument.Selection.NewLine   
        ActiveDocument.Selection.NewLine   
        ActiveDocument.Selection = "/** @} */ // "  
    end if   
End Sub  
  
'_________________________________________________________________   
'生成doxygen样式类描述   
Sub ClassDescription()   
    Dim win   
    set win = ActiveWindow   
    If win.type <> "Text" Then  
        MsgBox "This macro can only be run when a text editor window is active."  
    Else  
        className = ActiveDocument.Selection   
        if Len(className) <= 0 then   
           msgbox "lease select the class name"  
        else   
            StartLine = ActiveDocument.Selection.TopLine   
            ActiveDocument.Selection.GoToLine StartLine   
  
            if StartLine > 1 Then   
                ActiveDocument.Selection.MoveTo StartLine - 1, dsEndOfLine     
                ActiveDocument.Selection.NewLine   
            end if   
  
            if Instr(className, "class") >0 then   
                className = Ltrim(Right(className, Len(className)- Len("class")))   
            end if   
            if Instr(className, ":") >0  then   
                className = Trim(Left(className, Instr(className, ":")-1))   
            else   
                className = Trim(className)   
            end if   
            ActiveDocument.Selection = "/**"  
            ActiveDocument.Selection.NewLine   
            ActiveDocument.Selection = "* @class " + className   
            ActiveDocument.Selection.NewLine   
            ActiveDocument.Selection = "* @brief "  
            ActiveDocument.Selection.NewLine   
            ActiveDocument.Selection = "* "  
            ActiveDocument.Selection.NewLine   
            ActiveDocument.Selection = "* Detailed description."  
            ActiveDocument.Selection.NewLine   
            ActiveDocument.Selection = "*/"  
        end if   
    end if   
End Sub  
  
'_________________________________________________________________   
'生成doxygen样式组描述   
Sub GroupDescription()   
    Dim win   
    set win = ActiveWindow   
    If win.type <> "Text" Then  
        MsgBox "This macro can only be run when a text editor window is active."  
    Else  
        ActiveDocument.Selection.NewLine   
        ActiveDocument.Selection = "/**"  
        ActiveDocument.Selection.NewLine   
        ActiveDocument.Selection = "* @name "  
        ActiveDocument.Selection.NewLine   
        ActiveDocument.Selection = "* @brief "  
        ActiveDocument.Selection.NewLine   
        ActiveDocument.Selection = "* "  
        ActiveDocument.Selection.NewLine   
        ActiveDocument.Selection = "* Detailed description."  
        ActiveDocument.Selection.NewLine   
        ActiveDocument.Selection = "* @{"  
        ActiveDocument.Selection.NewLine   
        ActiveDocument.Selection = "*/"  
        ActiveDocument.Selection.NewLine   
        ActiveDocument.Selection.NewLine   
        ActiveDocument.Selection = "/** @} */ // "  
    end if   
End Sub  
  
'_________________________________________________________________   
'生成//或/** */类型的注释   
'------------------------------------------------------------------------------   
'FILE DESCRIPTION: These are useful macros by Adam Solesby[adam@solesby.com]   
'------------------------------------------------------------------------------   
  
  
'----------------------------------------------------------------------------------   
' This will comment/uncomment out single lines or blocks. Single lines are commented   
' with the same indention level. Blocks are commented at the beginning of the line.   
' Assign this to a key(e.g. ctrl-/) and it will toggle the current line/block of code.   
' This will handle both "//" and "'" style comments   
'----------------------------------------------------------------------------------   
  
Sub CustomCommentOut()   
'DESCRIPTION: Comments out a selected block of text.(ctrl-/)[by Adam Solesby -- http:// solesby.com ]   
    Dim win   
    set win = ActiveWindow   
    If win.type <> "Text" Then  
      MsgBox "This macro can only be run when a text editor window is active."  
    Else  
        TypeOfFile = FileType(ActiveDocument)   
        '   MsgBox "Type: " + CStr(TypeOfFile)   
        If TypeOfFile > 0 And TypeOfFile < 6 Then  
            If TypeOfFile > 3 Then  
                CommentType = "'"   ' VBShit   
                CommentWidth = 1   
            Else  
                CommentType = "//"  ' C++ and java style comments   
  
                CommentWidth = 2   
            End If  
            
            StartLine = ActiveDocument.Selection.TopLine   
            EndLine = ActiveDocument.Selection.BottomLine   
            If EndLine < StartLine Then  
                Temp = StartLine   
                StartLine = EndLine   
                EndLine = Temp   
            End If  
  
            ' single line with words selected   
            If EndLine = StartLine And Len(ActiveDocument.Selection) > 0 Then  
                s = ActiveDocument.Selection.Text   
                n = Len(ActiveDocument.Selection)   
  
                ' convert "/*sample text*/" => "sample text"("/*sample text*/" selected)   
                If left(s, 2) = "/*" and Right(s, 2) = "*/" Then  
                    ActiveDocument.Selection = Mid(s, 3, n - 4)   
                Else  
  
                    ActiveDocument.Selection.CharLeft   
                    ActiveDocument.Selection.CharLeft dsMove, 2   
                    ActiveDocument.Selection.CharRight dsExtend, n + 4   
                    s2 = ActiveDocument.Selection.Text   
                  
                    ' convert "/*sample text*/" => "sample text"("sample text" selected)   
                    If left(s2, 2) = "/*" and Right(s2, 2) = "*/" Then  
                        ActiveDocument.Selection = s   
  
                    ' convert "sample text" => "/*sample text*/"("sample text" selected)   
                    Else  
                        ActiveDocument.Selection.CharLeft   
                        ActiveDocument.Selection.CharRight dsMove, 2   
                        ActiveDocument.Selection.CharRight dsExtend, n   
                        ActiveDocument.Selection = "/*" & s & "*/"  
                    End If  
  
                End If  
                  
            ' Single line -- comment at start of text   
            '   have to check for comments at start of line and start of text   
            ElseIf EndLine = StartLine Then  
  
                ActiveDocument.Selection.StartOfLine dsFirstColumn   
                ActiveDocument.Selection.CharRight dsExtend, CommentWidth   
  
                If ActiveDocument.Selection = CommentType Then  
                    ActiveDocument.Selection.Delete   
                Else  
                    ActiveDocument.Selection.StartOfLine dsFirstText   
                    ActiveDocument.Selection.CharRight dsExtend, CommentWidth   
  
                    If ActiveDocument.Selection = CommentType Then  
  
                        ActiveDocument.Selection.CharLeft   
                        ActiveDocument.Selection.EndOfLine dsExtend   
                        s = ActiveDocument.Selection.Text   
                        s = LTrim(Mid(s, 3))   
                           
                        Do While Left(s, 1) = vbTab   
                            s = LTrim(Mid(s, 2))   
                        Loop  
                           
                        ActiveDocument.Selection = s   
                           
                    Else  
                        ActiveDocument.Selection.StartOfLine dsFirstText   
                        ActiveDocument.Selection = CommentType + vbTab + ActiveDocument.Selection   
                    End If  
                End If  
                ActiveDocument.Selection.StartOfLine dsFirstText   
  
            ' Multi - line -- comment at start of line   
            Else  
                CommentLoc = dsFirstColumn ' or dsFirstText if you prefer   
  
                ' check whether commenting on or off based on the _last_ line of selection   
                ActiveDocument.Selection.GoToLine EndLine   
                ActiveDocument.Selection.StartOfLine CommentLoc   
                ActiveDocument.Selection.CharRight dsExtend, CommentWidth   
                If ActiveDocument.Selection = CommentType Then  
                    bAddComment = False  
                Else  
                    bAddComment = True  
                End If  
                  
                ' work with strings so that we can do a single undo in editor   
                ActiveDocument.Selection.MoveTo StartLine, 1   
                ActiveDocument.Selection.MoveTo EndLine, dsEndOfLine, dsExtend   
                s = ActiveDocument.Selection.Text   
  
                If bAddComment Then  
                    s = CommentType & Replace(s, vbNewLine , vbNewLine & CommentType)   
                Else  
                    s = Replace(s, vbNewLine & CommentType, vbNewLine)   
                    s = Mid(s, Len(CommentType) + 1)   
                End If  
  
                ActiveDocument.Selection = s   
  
            End If  
        Else  
            MsgBox("Unable to comment out the highlighted text" + vbLf + _   
                "because the file type was unrecognized." + vbLf + _   
                "If the file has not yet been saved, " + vbLf + _   
                "please save it and try again.")   
        End If  
    End If  
End Sub  
'_________________________________________________________________   
'注释跳转   
'----------------------------------------------------------------------------------   
' This function toggles between end - of - line comments and line - before comment   
'   
'    // comment here   
'    void function();   
'               <==>       void function(); // comment here   
'   
'----------------------------------------------------------------------------------   
Sub CommentLineToggle()   
'DESCRIPTION: This toggles between end - of - line comments and line - before comment(ctrl - shift-/)[by Adam Solesby -- http:// solesby.com ]   
  
    StartLine   = ActiveDocument.Selection.TopLine   
    EndLine     = ActiveDocument.Selection.BottomLine   
    StartColumn = ActiveDocument.Selection.CurrentColumn   
  
    If StartLine <> EndLine Then Exit Sub  
  
    ActiveDocument.Selection.StartOfLine dsFirstText   
    ActiveDocument.Selection.CharRight dsExtend, 2   
  
    ' Check for comment - only line   
    If ActiveDocument.Selection = "//" Then  
  
        ' Found a previous - line comment, e.g.:   
        '   // this is a comment above the line   
        '   void function();   
  
        ' cut and paste on line below   
        ActiveDocument.Selection.SelectLine   
        ActiveDocument.Selection.Cut   
        ActiveDocument.Selection.EndOfLine   
        ActiveDocument.Selection.Paste   
        ActiveDocument.Selection.Backspace   
        bFound = ActiveDocument.Selection.FindText("//", dsMatchBackward)   
        If bFound Then  
            ActiveDocument.Selection.CharLeft   
            ActiveDocument.Selection.DeleteWhitespace dsHorizontal   
            ActiveDocument.Selection = " "  
        End If  
  
    Else  
        ActiveDocument.Selection.EndOfLine   
        ActiveDocument.Selection.SelectLine   
        bFound = ActiveDocument.Selection.FindText("//", dsMatchBackward)   
  
        If bFound Then  
  
            ' Found an end - of - line comment, e.g.:   
            '   void function() // this is a comment   
            If StartLine = ActiveDocument.Selection.CurrentLine Then  
  
                ' cut and paste on line above              
                ActiveDocument.Selection.CharLeft   
                ActiveDocument.Selection.NewLine   
                ActiveDocument.Selection.DeleteWhitespace dsHorizontal   
                ActiveDocument.Selection.LineDown dsExtend   
                ActiveDocument.Selection.Cut   
                ActiveDocument.Selection.LineUp   
                ActiveDocument.Selection.Paste   
                ActiveDocument.Selection.WordRight dsExtend   
                ActiveDocument.Selection.Copy   
                ActiveDocument.Selection.LineUp   
                ActiveDocument.Selection.StartOfLine dsFirstColumn   
                ActiveDocument.Selection.Paste   
  
            Else  
                ActiveDocument.Selection.MoveTo StartLine, StartColumn   
            End If  
        End If  
    End If  
End Sub  
  
  
'----------------------------------------------------------------------------------   
' This routine has many uses if you are trying to determine the type of source file.   
' This has been modified from the one included with DevStudio   
' Return value:  0 Unknown file type   
'               1 C - related file, this includes .c, .cpp, .cxx, .h, .hpp, .hxx   
'               2 Java - related file, this includes .jav, .java   
'               3 ODL - style file, .odl, .idl   
'               4 VBS - style file, .dsm   
'               5 VBS - style file, .asp   
'               6 HTML - style file, this includes .html, and .htm   
'               7 Resource file, .rc, .rc2   
'               8 Def - style file, .def   
' USE: Pass this function the document that you wish to get information for.   
'----------------------------------------------------------------------------------   
Function FileType(ByVal doc)   
    ext = doc.Name   
    FileType = 0   
    pos = Instr(ext, ".")   
    if pos > 0 then   
        Do While pos <> 1   
            ext = Mid(ext, pos, Len(ext) - pos + 1)   
            pos = Instr(ext, ".")   
        Loop  
        ext = LCase(ext)   
    End If  
  
    If ext = ".rc" Or ext = ".rc2" Then  
        FileType = 7   
    ElseIf doc.Language = dsCPP Then  
        FileType = 1   
    ElseIf doc.Language = dsJava Then  
        FileType = 2   
    ElseIf doc.Language = dsIDL Then  
        FileType = 3   
    ElseIf doc.Language = dsVBSMacro Then  
        FileType = 4     
    ElseIf ext = ".asp" Then  
        FileType = 5   
    ElseIf doc.Language = dsHTML_IE3 Or doc.Language = dsHTML_RFC1866 Then  
        FileType = 6     
    ElseIf ext = ".def" Then  
        FileType = 7   
    Else   
        FileType = 0   
    End If   
    'MsgBox "Ext:" + vbTab + ext + vbLf + "Lang:" + vbTab + doc.Language + vbLf + "Type:" + vbTab + CStr(FileType)   
End Function  
'/**
'* @file COMMENT.DSM
'* @brief VC6中添加文件头注释、类注释、函数注释、模块注释等。
'* @author Hao Liming
'* @date 2008-11-18 8:49:22
'* @version 0.8
'* <pre><b>copyright: </b></pre>
'* <pre><b>email: </b>hao.limin@gmail.com</pre>
'* <pre><b>company: </b>http://blog.csdn.net/donhao</pre>
'* <pre><b>All rights reserved.</b></pre>
'* <pre><b>modification:</b></pre>
'* <pre>v0.8 对代码进行了优化</pre>
'* <pre>v0.7 添加了新头文件注释</pre>
'* <pre>v0.6 修改了文件头注释中@version的错误</pre>
'* <pre>     修改了对inline函数生成注释时的错误</pre>
'* <pre>     修改了对static函数生成注释时的错误</pre>
'* <pre>     修改了将函数注释中返回为指针或引用例如为std::string &getName()时返回类型和函数名的错误</pre>
'* <pre>     修改了将函数注释中形参为指针或引用例如为std::string &getName(int &age)时参数类型的错误</pre>
'* <pre>v0.5 修改了文件注释内容与格式</pre>
'* <pre>     添加了类描述;</pre>
'* <pre>     修改了函数返回void以及函数参数为void时存在的问题</pre>
'* <pre>v0.4 修正了不能为跨行函数签名插入注释的问题</pre>
'* <pre>     修正了参数列表带有默认值的情况</pre>
'* <pre>     修正了把virtual作为返回值的问题</pre>
'* <pre>     修正了构造函数和析构函数注释的问题</pre>
'* <pre>v0.3 添加了Comment Out、注释转移功能。这些功能由Adam Solesby[adam@solesby.com]实现</pre>
'* <pre>v0.2 修正了文件注释中参数信息提取的错误</pre>
'* <pre>     修正了插入注释时差入行的问题</pre>
'* <pre>v0.1 基于http://blog.csdn.net/nicholasmax ... /08/14/1742223.aspx实现了函数注释、文件注释、简要注释、详细注释、模块注释、注释、公开变量注释、项目编号注释 </pre>
'*/

Function StripTabs(ByVal MyStr)
    Do While InStr(MyStr, vbTab) <> 0
        MyStr = Right(MyStr, Len(MyStr) - InStr(MyStr, vbTab))
    Loop
    StripTabs = Trim(MyStr)
End Function
'_________________________________________________________________
'生成Doxygen样式的函数注释
Sub FunctionDescription()
        Dim win
        set win = ActiveWindow
        If win.type <> "Text" Then
          MsgBox "This macro can only be run when a text editor window is active."
        Else

           '判断所选择的行
                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 & StripTabs(Trim(ActiveDocument.Selection))
                        tmpLine = tmpLine +1
                loop
       
            '把回车换成空格
                Header = replace(Header, vbcrlf, " ")
       
                ActiveDocument.Selection.GoToLine StartLine
       
                   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

                Loc = InStr(Header, "(") - 1
                       Loc2 = InStr(Header, ")")
                if Loc > 0 And Loc2 > 0 then
                    fcName = Left(Header, Loc)
                    Header = Right(Header, Len(Header) - Len(fcName))

                    Trim(fcName)

                '得到函数名称
                    Do While InStr(fcName, " ") <> 0
                        retTp = retTp + Left(fcName, InStr(fcName, " "))
                        fcName = Right(fcName, Len(fcName) - InStr(fcName, " "))
                    loop
                               
                                '如果函数名称第一个字符为"*"或"&",则做为返回值最后一个字符
                                if InStr(fcName, "*") =1 then
                                    retTp = Rtrim(retTp) + "*"
                                        fcName = Ltrim(Right(fcName, Len(fcName) - 1))
                                end if
                                if InStr(fcName, "&") =1 then
                                    retTp = Rtrim(retTp) + "&"
                                        fcName = Ltrim(Right(fcName, Len(fcName) - 1))
                                end if


                '对返回值进行处理
                                '去掉virtual
                                if InStr(retTp, "virtual") <> 0 Then
                                    retTp = Ltrim(Right(retTp, Len(retTp) - Len("virtual")))
                                end if
       
                                '去掉inline
                                if InStr(retTp, "inline") <> 0 Then
                                    retTp = Ltrim(Right(retTp, Len(retTp) - Len("inline")))
                                end if

                                '去掉static
                                if InStr(retTp, "static") <> 0 Then
                                    retTp = Ltrim(Right(retTp, Len(retTp) - Len("static")))
                                end if
                               
                                iPrm = 0
                    iPrmA = 0
                    prms = Header

                    Do While InStr(prms, ",") <> 0
                        iPrm = iPrm + 1
                        prms = Right(prms, Len(prms) - InStr(prms, ","))
                    Loop
              
                    If iPrm > 0 Then
                        iPrm = iPrm + 1
                        iPrmA = iPrm
                        Redim ParamArr(iPrm)
                        Do While InStr(header, ",") <> 0
                            ParamArr(iPrm) = Left(Header, InStr(Header, ",") - 1)
            
                            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
     
                        If InStr(ParamArr(iPrm), ")") <> 0 Then
                            ParamArr(iPrm) = Left(ParamArr(iPrm), InStr(ParamArr(iPrm), ")") - 1)
                            Trim(ParamArr(iPrm))
                        End If
                    Else
                        Redim ParamArr(1)
                        Header = Right(Header, Len(Header) - 1)
                        Trim(Header)
                        ParamArr(1) = StripTabs(Header)
                        If InStr(ParamArr(1), ")") <> 1 Then
                            ParamArr(1) = Left(ParamArr(1), InStr(ParamArr(1), ")") - 1)
                            Trim(ParamArr(1))
                            iPrmA = 1
                                                if ParamArr(1) = "void" then
                                                  iPrmA = 0
                                                end if
                        End If
                    End If


                    if ActiveDocument.Selection.CurrentLine <> 1 Then
                        ActiveDocument.Selection.GoToLine ActiveDocument.Selection.CurrentLine - 1
                        ActiveDocument.Selection.MoveTo ActiveDocument.Selection.CurrentLine, dsEndOfLine   
                        ActiveDocument.Selection.NewLine
                         end if

                    ActiveDocument.Selection = "/** "
                    ActiveDocument.Selection.NewLine

            
                                '判断是构造函数还是析构函数
                                if  len(Trim(RetTp)) > 0 Then
                        ActiveDocument.Selection = "* @brief " + fcName +" "
                                else
                                    '为构造函数
                                    if Instr(fcName, "~") <> 0 then
                                   ActiveDocument.Selection = "* @brief " + "Destructor for " + Right(fcName, len(fcName)-1) +"."
                                        '为析构函数
                                        else
                                                ActiveDocument.Selection = "* @brief " + "Constructor for " + fcName +"."       
                                        end if                                        
                                end if

                ActiveDocument.Selection.NewLine
                                ActiveDocument.Selection = "* "
                ActiveDocument.Selection.NewLine
                ActiveDocument.Selection = "* Detailed description."


                    Last = iPrmA
                    Do While iPrmA <> 0
                        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) = StripTabs(ParamArr(iPrmA))

                        if iPrmA = Last AND Last <> 1 then
                            ParamArr(iPrmA) = Right(ParamArr(iPrmA), Len(ParamArr(iPrmA)) - 1)
                        End If
                        ActiveDocument.Selection.NewLine
                            
                                        '首先判断参数列表中有没有'='号,如果有,则等号左边为参数名,右边为默认值。
                                        Dim defautValue
                        If InStr(ParamArr(iPrmA), "=") <> 0 Then
                                            defautValue = Ltrim(Right(ParamArr(iPrmA), Len(ParamArr(iPrmA)) - InStr(ParamArr(iPrmA), "=")))
                            ParamArr(iPrmA) = Rtrim(Left(ParamArr(iPrmA), InStr(ParamArr(iPrmA), "=") - 1))
                                        end if

                                    Do While InStr(defautValue, " ") <> 0
                            defautValue = Right(defautValue, Len(defautValue) - InStr(defautValue, " "))
                        loop

                                    Do While InStr(ParamArr(iPrmA), " ") <> 0
                            ParamArr(iPrmA) = Right(ParamArr(iPrmA), Len(ParamArr(iPrmA)) - InStr(ParamArr(iPrmA), " "))
                        loop

                                        '如果形参形如std::string &name时,应该将引用符号放到前边
                                    if InStr(ParamArr(iPrmA), "*") =1 OR InStr(ParamArr(iPrmA), "&") =1 then
                                            ParamArr(iPrmA) = Ltrim(Right(ParamArr(iPrmA), Len(ParamArr(iPrmA)) - 1))
                                    end if

                        if Len(Trim(defautValue)) > 0 Then
                            ActiveDocument.Selection = "* @param[in] " + LTrim(ParamArr(iPrmA)) +" Defaults to " + Trim(defautValue) + "."
                                        else
                                            ActiveDocument.Selection = "* @param[in] " + LTrim(ParamArr(iPrmA)) +" "
                                        end if
                        iPrmA = iPrmA - 1
                    Loop

                    ActiveDocument.Selection.NewLine
                                if  len(Trim(RetTp)) > 0 And Trim(RetTp) <> "void" Then
                        ActiveDocument.Selection = "* @return " + RetTp +" "
                        ActiveDocument.Selection.NewLine                    
                                end if
                    ActiveDocument.Selection = "*/"
                Else
                    MsgBox("It is possible that the function you are trying to"+_
                        " work with has a syntax error.")
                End if
            End If
        End if
End Sub

'_________________________________________________________________
'生成doxygen样式的公开变量的注释
Sub MemberDescription()
        Dim win
        set win = ActiveWindow
        If win.type <> "Text" Then
            MsgBox "This macro can only be run when a text editor window is active."
        Else
        ActiveDocument.Selection = ActiveDocument.Selection +" /**<  */"
    End if
End Sub

'生成doxygen样式的一般通用的注释
Sub DetailDescription()
        Dim win
        set win = ActiveWindow
        If win.type <> "Text" Then
            MsgBox "This macro can only be run when a text editor window is active."
        Else
        ActiveDocument.Selection.NewLine
        ActiveDocument.Selection = "/** "
        ActiveDocument.Selection.NewLine
        ActiveDocument.Selection = "* @brief "
        ActiveDocument.Selection.NewLine
        ActiveDocument.Selection = "* "
        ActiveDocument.Selection.NewLine
        ActiveDocument.Selection = "* Detailed description."
        ActiveDocument.Selection.NewLine
        ActiveDocument.Selection = "*/"
        end if
End Sub

'_________________________________________________________________
'生成doxygen样式的简要注释
Sub BriefDescription()
        Dim win
        set win = ActiveWindow
        If win.type <> "Text" Then
            MsgBox "This macro can only be run when a text editor window is active."
        Else
            ActiveDocument.Selection.NewLine
        ActiveDocument.Selection = "/** @brief  */"
        end if
End Sub

'_________________________________________________________________
'生成doxygen样式的文件描述
Sub FileDescription()
        Dim win
        set win = ActiveWindow
        If win.type <> "Text" Then
            MsgBox "This macro can only be run when a text editor window is active."
        Else
                if ActiveDocument.Selection.CurrentLine <> 1 Then
                ActiveDocument.Selection.GoToLine ActiveDocument.Selection.CurrentLine - 1
                        ActiveDocument.Selection.MoveTo ActiveDocument.Selection.CurrentLine, dsEndOfLine   
                ActiveDocument.Selection.NewLine
                end if
              ActiveDocument.Selection = "/**"
        ActiveDocument.Selection.NewLine
        ActiveDocument.Selection = "* @file " + ActiveDocument.Name
        ActiveDocument.Selection.NewLine
        ActiveDocument.Selection = "* @brief "
        ActiveDocument.Selection.NewLine
        ActiveDocument.Selection = "* @author ***"
        ActiveDocument.Selection.NewLine
        ActiveDocument.Selection = "* @date "
        ActiveDocument.Selection = DATE + TIME
        ActiveDocument.Selection.NewLine
                ActiveDocument.Selection = "* @version "
                ActiveDocument.Selection.NewLine
        ActiveDocument.Selection = "* <pre><b>copyright: </b></pre>"
        ActiveDocument.Selection.NewLine
        ActiveDocument.Selection = "* <pre><b>email: </b>***@***</pre>"
        ActiveDocument.Selection.NewLine
                ActiveDocument.Selection = "* <pre><b>company: </b>http://</pre>"
        ActiveDocument.Selection.NewLine
                ActiveDocument.Selection = "* <pre><b>All rights reserved.</b></pre>"
        ActiveDocument.Selection.NewLine
                ActiveDocument.Selection = "* <pre><b>modification:</b></pre>"
        ActiveDocument.Selection.NewLine
                ActiveDocument.Selection = "* <pre>Write modifications here.</pre>"
        ActiveDocument.Selection.NewLine
        ActiveDocument.Selection = "*/"
    end if
End Sub


'_________________________________________________________________
'生成doxygen样式的新文件描述
Sub NewFileDescription()
        Dim win
        set win = ActiveWindow
        If win.type <> "Text" Then
            MsgBox "This macro can only be run when a text editor window is active."
        Else
                if ActiveDocument.Selection.CurrentLine <> 1 Then
                ActiveDocument.Selection.GoToLine ActiveDocument.Selection.CurrentLine - 1
                        ActiveDocument.Selection.MoveTo ActiveDocument.Selection.CurrentLine, dsEndOfLine   
                ActiveDocument.Selection.NewLine
                end if
              ActiveDocument.Selection = "/**"
        ActiveDocument.Selection.NewLine
        ActiveDocument.Selection = "* @file " + ActiveDocument.Name
        ActiveDocument.Selection.NewLine
        ActiveDocument.Selection = "* @brief "
        ActiveDocument.Selection.NewLine
        ActiveDocument.Selection = "* @author ***"
        ActiveDocument.Selection.NewLine
        ActiveDocument.Selection = "* @date "
        ActiveDocument.Selection = DATE + TIME
        ActiveDocument.Selection.NewLine
                ActiveDocument.Selection = "* @version "
                ActiveDocument.Selection.NewLine
        ActiveDocument.Selection = "* <pre><b>copyright: </b></pre>"
        ActiveDocument.Selection.NewLine
        ActiveDocument.Selection = "* <pre><b>email: </b>***@***</pre>"
        ActiveDocument.Selection.NewLine
                ActiveDocument.Selection = "* <pre><b>company: </b>http://</pre>"
        ActiveDocument.Selection.NewLine
                ActiveDocument.Selection = "* <pre><b>All rights reserved.</b></pre>"
        ActiveDocument.Selection.NewLine
                ActiveDocument.Selection = "* <pre><b>modification:</b></pre>"
        ActiveDocument.Selection.NewLine
                ActiveDocument.Selection = "* <pre>Write modifications here.</pre>"
        ActiveDocument.Selection.NewLine
        ActiveDocument.Selection = "*/"
                if InStr(ActiveDocument.Name, ".") > 0 then
                    if Right(ActiveDocument.Name, Len(ActiveDocument.Name) - InStr(ActiveDocument.Name, ".")) = "h"  _
                        or Right(ActiveDocument.Name, Len(ActiveDocument.Name) - InStr(ActiveDocument.Name, ".")) = "hpp" _
                        or Right(ActiveDocument.Name, Len(ActiveDocument.Name) - InStr(ActiveDocument.Name, ".")) = "hh" then
                            def = "_" + UCase(Left(ActiveDocument.Name, InStr(ActiveDocument.Name, ".") - 1)_
                                + "_" + Right(ActiveDocument.Name, Len(ActiveDocument.Name) - InStr(ActiveDocument.Name, ".")))
                ActiveDocument.Selection.NewLine
                                ActiveDocument.Selection = "#ifndef " + def
                                ActiveDocument.Selection.NewLine
                                ActiveDocument.Selection = "#define " + def
                                ActiveDocument.Selection.NewLine
                                ActiveDocument.Selection.NewLine
                                ActiveDocument.Selection = "#endif // "  + def
                                ActiveDocument.Selection.NewLine
                        end if
                end if

    end if
End Sub
'_________________________________________________________________
'生成doxygen样式的项目编号描述
Sub ItemDescription()
        Dim win
        set win = ActiveWindow
        If win.type <> "Text" Then
            MsgBox "This macro can only be run when a text editor window is active."
        Else
            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 = "* - "
        ActiveDocument.Selection.NewLine
        ActiveDocument.Selection = "* -# "
        ActiveDocument.Selection.NewLine
        ActiveDocument.Selection = "* -# "
        ActiveDocument.Selection.NewLine
        ActiveDocument.Selection = "*/"
        end if
End Sub

'_________________________________________________________________
'生成doxygen样式模块描述
Sub ModuleDescription()
        Dim win
        set win = ActiveWindow
        If win.type <> "Text" Then
            MsgBox "This macro can only be run when a text editor window is active."
        Else
            ActiveDocument.Selection.NewLine
        ActiveDocument.Selection = "/**"
        ActiveDocument.Selection.NewLine
        ActiveDocument.Selection = "* @defgroup "
        ActiveDocument.Selection.NewLine
        ActiveDocument.Selection = "* @brief "
        ActiveDocument.Selection.NewLine
        ActiveDocument.Selection = "* "
        ActiveDocument.Selection.NewLine
        ActiveDocument.Selection = "* Detailed description."
        ActiveDocument.Selection.NewLine
        ActiveDocument.Selection = "* @{"
        ActiveDocument.Selection.NewLine
        ActiveDocument.Selection = "*/"
        ActiveDocument.Selection.NewLine
        ActiveDocument.Selection.NewLine
        ActiveDocument.Selection = "/** @} */ // "
        end if
End Sub

'_________________________________________________________________
'生成doxygen样式类描述
Sub ClassDescription()
        Dim win
        set win = ActiveWindow
        If win.type <> "Text" Then
            MsgBox "This macro can only be run when a text editor window is active."
        Else
            className = ActiveDocument.Selection
                if Len(className) <= 0 then
                   msgbox "Please select the class name"
        else
                    StartLine = ActiveDocument.Selection.TopLine
            ActiveDocument.Selection.GoToLine StartLine

            if StartLine > 1 Then
                ActiveDocument.Selection.MoveTo StartLine - 1, dsEndOfLine  
                ActiveDocument.Selection.NewLine
                end if

                        if Instr(className, "class") >0 then
                            className = Ltrim(Right(className, Len(className)- Len("class")))
                        end if
                        if Instr(className, ":") >0  then
                        className = Trim(Left(className, Instr(className, ":")-1))
                        else
                            className = Trim(className)
                        end if
                        ActiveDocument.Selection = "/**"
            ActiveDocument.Selection.NewLine
            ActiveDocument.Selection = "* @class " + className
            ActiveDocument.Selection.NewLine
            ActiveDocument.Selection = "* @brief "
            ActiveDocument.Selection.NewLine
            ActiveDocument.Selection = "* "
            ActiveDocument.Selection.NewLine
            ActiveDocument.Selection = "* Detailed description."
            ActiveDocument.Selection.NewLine
            ActiveDocument.Selection = "*/"
                end if
        end if
End Sub

'_________________________________________________________________
'生成doxygen样式组描述
Sub GroupDescription()
        Dim win
        set win = ActiveWindow
        If win.type <> "Text" Then
            MsgBox "This macro can only be run when a text editor window is active."
        Else
        ActiveDocument.Selection.NewLine
        ActiveDocument.Selection = "/**"
        ActiveDocument.Selection.NewLine
        ActiveDocument.Selection = "* @name "
        ActiveDocument.Selection.NewLine
        ActiveDocument.Selection = "* @brief "
        ActiveDocument.Selection.NewLine
        ActiveDocument.Selection = "* "
        ActiveDocument.Selection.NewLine
        ActiveDocument.Selection = "* Detailed description."
        ActiveDocument.Selection.NewLine
        ActiveDocument.Selection = "* @{"
        ActiveDocument.Selection.NewLine
        ActiveDocument.Selection = "*/"
        ActiveDocument.Selection.NewLine
            ActiveDocument.Selection.NewLine
        ActiveDocument.Selection = "/** @} */ // "
        end if
End Sub

'_________________________________________________________________
'生成//或/** */类型的注释
'------------------------------------------------------------------------------
'FILE DESCRIPTION: These are useful macros by Adam Solesby[adam@solesby.com]
'------------------------------------------------------------------------------


'----------------------------------------------------------------------------------
' This will comment/uncomment out single lines or blocks. Single lines are commented
' with the same indention level. Blocks are commented at the beginning of the line.
' Assign this to a key(e.g. ctrl-/) and it will toggle the current line/block of code.
' This will handle both "//" and "'" style comments
'----------------------------------------------------------------------------------

Sub CustomCommentOut()
'DESCRIPTION: Comments out a selected block of text.(ctrl-/)[by Adam Solesby -- http:// solesby.com ]
        Dim win
        set win = ActiveWindow
        If win.type <> "Text" Then
          MsgBox "This macro can only be run when a text editor window is active."
        Else
                TypeOfFile = FileType(ActiveDocument)
                '        MsgBox "Type: " + CStr(TypeOfFile)
                If TypeOfFile > 0 And TypeOfFile < 6 Then
                        If TypeOfFile > 3 Then
                                CommentType = "'"        ' VBShit
                                CommentWidth = 1
                        Else
                                CommentType = "//"        ' C++ and java style comments

                                CommentWidth = 2
                        End If
                 
                        StartLine = ActiveDocument.Selection.TopLine
                        EndLine = ActiveDocument.Selection.BottomLine
                        If EndLine < StartLine Then
                                Temp = StartLine
                                StartLine = EndLine
                                EndLine = Temp
                        End If

                        ' single line with words selected
                        If EndLine = StartLine And Len(ActiveDocument.Selection) > 0 Then
                                s = ActiveDocument.Selection.Text
                                n = Len(ActiveDocument.Selection)

                                ' convert "/*sample text*/" => "sample text"("/*sample text*/" selected)
                                If left(s, 2) = "/*" and Right(s, 2) = "*/" Then
                                        ActiveDocument.Selection = Mid(s, 3, n - 4)
                                Else

                                        ActiveDocument.Selection.CharLeft
                                        ActiveDocument.Selection.CharLeft dsMove, 2
                                        ActiveDocument.Selection.CharRight dsExtend, n + 4
                                        s2 = ActiveDocument.Selection.Text
                               
                                        ' convert "/*sample text*/" => "sample text"("sample text" selected)
                                        If left(s2, 2) = "/*" and Right(s2, 2) = "*/" Then
                                                ActiveDocument.Selection = s

                                        ' convert "sample text" => "/*sample text*/"("sample text" selected)
                                        Else
                                                ActiveDocument.Selection.CharLeft
                                                ActiveDocument.Selection.CharRight dsMove, 2
                                                ActiveDocument.Selection.CharRight dsExtend, n
                                                ActiveDocument.Selection = "/*" & s & "*/"
                                        End If

                                End If
                               
                        ' Single line -- comment at start of text
                        '   have to check for comments at start of line and start of text
                        ElseIf EndLine = StartLine Then

                                ActiveDocument.Selection.StartOfLine dsFirstColumn
                                ActiveDocument.Selection.CharRight dsExtend, CommentWidth

                                If ActiveDocument.Selection = CommentType Then
                                        ActiveDocument.Selection.Delete
                                Else
                                        ActiveDocument.Selection.StartOfLine dsFirstText
                                        ActiveDocument.Selection.CharRight dsExtend, CommentWidth

                                        If ActiveDocument.Selection = CommentType Then

                                                ActiveDocument.Selection.CharLeft
                                                ActiveDocument.Selection.EndOfLine dsExtend
                                                s = ActiveDocument.Selection.Text
                                                s = LTrim(Mid(s, 3))
                                               
                                                Do While Left(s, 1) = vbTab
                                                        s = LTrim(Mid(s, 2))
                                                Loop
                                               
                                                ActiveDocument.Selection = s
                                               
                                        Else
                                                ActiveDocument.Selection.StartOfLine dsFirstText
                                                ActiveDocument.Selection = CommentType + vbTab + ActiveDocument.Selection
                                        End If
                                End If
                                ActiveDocument.Selection.StartOfLine dsFirstText

                        ' Multi - line -- comment at start of line
                        Else
                                CommentLoc = dsFirstColumn ' or dsFirstText if you prefer

                                ' check whether commenting on or off based on the _last_ line of selection
                                ActiveDocument.Selection.GoToLine EndLine
                                ActiveDocument.Selection.StartOfLine CommentLoc
                                ActiveDocument.Selection.CharRight dsExtend, CommentWidth
                                If ActiveDocument.Selection = CommentType Then
                                        bAddComment = False
                                Else
                                        bAddComment = True
                                End If
                               
                                ' work with strings so that we can do a single undo in editor
                                ActiveDocument.Selection.MoveTo StartLine, 1
                                ActiveDocument.Selection.MoveTo EndLine, dsEndOfLine, dsExtend
                                s = ActiveDocument.Selection.Text

                                If bAddComment Then
                                        s = CommentType & Replace(s, vbNewLine , vbNewLine & CommentType)
                                Else
                                        s = Replace(s, vbNewLine & CommentType, vbNewLine)
                                        s = Mid(s, Len(CommentType) + 1)
                                End If

                                ActiveDocument.Selection = s

                        End If
                Else
                        MsgBox("Unable to comment out the highlighted text" + vbLf + _
                                "because the file type was unrecognized." + vbLf + _
                                "If the file has not yet been saved, " + vbLf + _
                                "please save it and try again.")
                End If
        End If
End Sub
'_________________________________________________________________
'注释跳转
'----------------------------------------------------------------------------------
' This function toggles between end - of - line comments and line - before comment
'
'    // comment here
'    void function();
'                                <==>       void function(); // comment here
'
'----------------------------------------------------------------------------------
Sub CommentLineToggle()
'DESCRIPTION: This toggles between end - of - line comments and line - before comment(ctrl - shift-/)[by Adam Solesby -- http:// solesby.com ]

        StartLine   = ActiveDocument.Selection.TopLine
        EndLine     = ActiveDocument.Selection.BottomLine
        StartColumn = ActiveDocument.Selection.CurrentColumn

        If StartLine <> EndLine Then Exit Sub

        ActiveDocument.Selection.StartOfLine dsFirstText
        ActiveDocument.Selection.CharRight dsExtend, 2

        ' Check for comment - only line
        If ActiveDocument.Selection = "//" Then

                ' Found a previous - line comment, e.g.:
                '         // this is a comment above the line
                '        void function();

                ' cut and paste on line below
                ActiveDocument.Selection.SelectLine
                ActiveDocument.Selection.Cut
                ActiveDocument.Selection.EndOfLine
                ActiveDocument.Selection.Paste
                ActiveDocument.Selection.Backspace
                bFound = ActiveDocument.Selection.FindText("//", dsMatchBackward)
                If bFound Then
                        ActiveDocument.Selection.CharLeft
                        ActiveDocument.Selection.DeleteWhitespace dsHorizontal
                        ActiveDocument.Selection = " "
                End If

        Else
                ActiveDocument.Selection.EndOfLine
                ActiveDocument.Selection.SelectLine
                bFound = ActiveDocument.Selection.FindText("//", dsMatchBackward)

                If bFound Then

                        ' Found an end - of - line comment, e.g.:
                        '         void function() // this is a comment
                        If StartLine = ActiveDocument.Selection.CurrentLine Then

                                ' cut and paste on line above                       
                                ActiveDocument.Selection.CharLeft
                                ActiveDocument.Selection.NewLine
                                ActiveDocument.Selection.DeleteWhitespace dsHorizontal
                                ActiveDocument.Selection.LineDown dsExtend
                                ActiveDocument.Selection.Cut
                                ActiveDocument.Selection.LineUp
                                ActiveDocument.Selection.Paste
                                ActiveDocument.Selection.WordRight dsExtend
                                ActiveDocument.Selection.Copy
                                ActiveDocument.Selection.LineUp
                                ActiveDocument.Selection.StartOfLine dsFirstColumn
                                ActiveDocument.Selection.Paste

                        Else
                                ActiveDocument.Selection.MoveTo StartLine, StartColumn
                        End If
                End If
        End If
End Sub


'----------------------------------------------------------------------------------
' This routine has many uses if you are trying to determine the type of source file.
' This has been modified from the one included with DevStudio
' Return value:  0 Unknown file type
'               1 C - related file, this includes .c, .cpp, .cxx, .h, .hpp, .hxx
'               2 Java - related file, this includes .jav, .java
'               3 ODL - style file, .odl, .idl
'               4 VBS - style file, .dsm
'               5 VBS - style file, .asp
'               6 HTML - style file, this includes .html, and .htm
'               7 Resource file, .rc, .rc2
'               8 Def - style file, .def
' USE: Pass this function the document that you wish to get information for.
'----------------------------------------------------------------------------------
Function FileType(ByVal doc)
        ext = doc.Name
        FileType = 0
        pos = Instr(ext, ".")
        if pos > 0 then
                Do While pos <> 1
                        ext = Mid(ext, pos, Len(ext) - pos + 1)
                        pos = Instr(ext, ".")
                Loop
                ext = LCase(ext)
        End If

        If ext = ".rc" Or ext = ".rc2" Then
                FileType = 7
        ElseIf doc.Language = dsCPP Then
                FileType = 1
        ElseIf doc.Language = dsJava Then
                FileType = 2
        ElseIf doc.Language = dsIDL Then
                FileType = 3
        ElseIf doc.Language = dsVBSMacro Then
                FileType = 4  
        ElseIf ext = ".asp" Then
                FileType = 5
        ElseIf doc.Language = dsHTML_IE3 Or doc.Language = dsHTML_RFC1866 Then
                FileType = 6  
        ElseIf ext = ".def" Then
                FileType = 7
        Else
                FileType = 0
        End If
        'MsgBox "Ext:" + vbTab + ext + vbLf + "Lang:" + vbTab + doc.Language + vbLf + "Type:" + vbTab + CStr(FileType)
End Function



本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/donhao/archive/2010/05/14/5591980.aspx
因为执着,所以成功
您需要登录后才可以回帖 登录 | 加入社区!

C语言 ( 粤ICP备11042647号-2 )

GMT+8, 2012-2-7 23:07

©2009-2011 cyuyan.com.cn

回顶部