vc2008 中使用宏来添加注释的步骤
2014-04-10 22:44
447 查看
在VS2008里面通过宏可以记录下注释信息,产生一个注释文件,每次需要的时候直接增加到类文件里面即可,方法如下:
在vc中:tools->Macros->MacrosExplores 打开宏浏览器
然后新建个宏工程 宏文件(Module1)名称修改为COMMENT 然后 将下列代码加入
然后打开 工具->宏->宏资源管理器 双击宏名称就可以使用了。
PS:
VS2008注释宏不能运行的解决办法
搜索 文件 vsmsvr.exe.config ( 默认C盘安装的路径为 C:\Program Files\Common Files\microsoft shared\VSA\9.0\VsaEnv)。。
打开这个文件在里面的runtime节点下增加 <AllowDComReflection enabled="1"/> 或<AllowDComReflection enabled="true"/> 一句,如下文件内容。。
在vc中:tools->Macros->MacrosExplores 打开宏浏览器
然后新建个宏工程 宏文件(Module1)名称修改为COMMENT 然后 将下列代码加入
然后打开 工具->宏->宏资源管理器 双击宏名称就可以使用了。
'/** '* @file COMMENT.DSM '* @brief 添加文件头注释、类注释、函数注释、模块注释等。 '* @author lishaojie '* @date 2014-04-10 21:45:00 '* @version 0.1 '* \pre '* \details '* \copyright: All rights reserved '* \email: '* \company: '* \modification: '*/ Imports System Imports EnvDTE Imports EnvDTE80 Imports EnvDTE90 Imports System.Diagnostics Public Module COMMENT 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样式的函数注释 Public Sub FunctionDescription() '判断所选择的行 Dim StartLine, endLine, Temp, tmpLine, Header, Reti, Loc, RetTp, Loc2, fcName, iPrm, iPrmA, prms, ParamArr, Last StartLine = ActiveDocument.Selection.TopLine endLine = ActiveDocument.Selection.BottomLine If endLine < StartLine Then Temp = StartLine StartLine = endLine endLine = Temp End If '如果行数大于,则将各行的字符串合成一个字符串 tmpLine = StartLine Do While tmpLine <= endLine ActiveDocument.Selection.GoToLine(tmpLine) ActiveDocument.Selection.SelectLine() Header = Header & StripTabs(Trim(ActiveDocument.Selection.text)) 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, 0) ActiveDocument.Selection.EndOfLine() ActiveDocument.Selection.NewLine() End If ActiveDocument.Selection.text = "/** " ActiveDocument.Selection.NewLine() '判断是构造函数还是析构函数 If Len(Trim(RetTp)) > 0 Then ActiveDocument.Selection.text = "* @brief " + fcName + " " Else '为构造函数 If InStr(fcName, "~") <> 0 Then ActiveDocument.Selection.text = "* @brief " + "Destructor for " + Right(fcName, Len(fcName) - 1) + "." '为析构函数 Else ActiveDocument.Selection.text = "* @brief " + "Constructor for " + fcName + "." End If End If ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "* " ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "* 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.text = "* @param[in] " + LTrim(ParamArr(iPrmA)) + " Defaults to " + Trim(defautValue) + "." Else ActiveDocument.Selection.text = "* @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.text = "* @return " + RetTp + " " ActiveDocument.Selection.NewLine() End If ActiveDocument.Selection.text = "*/" Else MsgBox("It is possible that the function you are trying to work with has a syntax error.") End If End If End Sub '生成doxygen样式的简要注释 Public Sub BriefDescription() ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "/** @brief */" End Sub '生成doxygen样式的公开变量的注释 Public Sub MemberDescription() ActiveDocument.Selection.text = ActiveDocument.Selection.text + " /**< */" End Sub '生成doxygen样式的一般通用的注释 Public Sub DetailDescription() ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "/** " ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "* @brief " ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "* " ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "* Detailed description." ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "*/" End Sub '生成doxygen样式的一般通用的注释 Public Sub Define() ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "#define " End Sub '生成doxygen样式的一般通用的注释 Public Sub Include() ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "#include " End Sub '生成doxygen样式的一般通用的注释 Public Sub TypedefStruct() ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "typedef struct" ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "{" ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "}TSP_PACKED _Struct;" ActiveDocument.Selection.NewLine() End Sub '生成doxygen样式的一般通用的注释 Public Sub TypedefEnum() ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "typedef Enum" ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "{" ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "}_Enum;" ActiveDocument.Selection.NewLine() End Sub '生成doxygen样式的文件描述 Public Sub FileDescription() If ActiveDocument.Selection.CurrentLine <> 1 Then ActiveDocument.Selection.GoToLine(ActiveDocument.Selection.CurrentLine - 1) ActiveDocument.Selection.MoveTo(ActiveDocument.Selection.CurrentLine, 0) ActiveDocument.Selection.EndOfLine() ActiveDocument.Selection.NewLine() End If ActiveDocument.Selection.text = "/**" ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "* @file " + ActiveDocument.Name ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "* @brief " ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "* @author ***" ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "* @date " ActiveDocument.Selection.text = DateTime.Today + " " + TimeOfDay ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "* @version " ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "* \pre ***" ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "* \details ***" ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "* \copyright: *** All rights reserved." ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "* \email: ***@***" ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "* \company: http://" ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "* \modification:" ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "* \Write modifications here." ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "*/" End Sub '生成doxygen样式的新文件描述 Public Sub NewFileDescription() If ActiveDocument.Selection.CurrentLine <> 1 Then ActiveDocument.Selection.GoToLine(ActiveDocument.Selection.CurrentLine - 1) ActiveDocument.Selection.MoveTo(ActiveDocument.Selection.CurrentLine, 0) ActiveDocument.Selection.EndOfLine() ActiveDocument.Selection.NewLine() End If ActiveDocument.Selection.text = "/**" ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "* @file " + ActiveDocument.Name ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "* @brief " ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "* @author ***" ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "* @date " ActiveDocument.Selection.text = DateTime.Today + " " + TimeOfDay ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "* @version " ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "* \pre ***" ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "* \details ***" ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "* \copyright: *** All rights reserved." ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "* \email: ***@***" ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "* \company: http://" ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "* \modification:" ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "* \Write modifications here." ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "*/" 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 Dim def def = "_" + UCase(Left(ActiveDocument.Name, InStr(ActiveDocument.Name, ".") - 1) _ + "_" + Right(ActiveDocument.Name, Len(ActiveDocument.Name) - InStr(ActiveDocument.Name, "."))) ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "#ifndef " + def ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "#define " + def ActiveDocument.Selection.NewLine() ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "#endif " ActiveDocument.Selection.NewLine() End If If Right(ActiveDocument.Name, Len(ActiveDocument.Name) - InStr(ActiveDocument.Name, ".")) = "c" _ Or Right(ActiveDocument.Name, Len(ActiveDocument.Name) - InStr(ActiveDocument.Name, ".")) = "cpp" Then Dim def def = "#include " + Chr(34) + Left(ActiveDocument.Name, InStr(ActiveDocument.Name, ".")) + "h" + Chr(34) ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = def ActiveDocument.Selection.NewLine() End If End If End Sub '生成doxygen样式的项目编号描述 Public Sub ItemDescription() ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "/**" ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "* " ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "* - " ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "* -# " ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "* -# " ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "* - " ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "* -# " ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "* -# " ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "*/" End Sub '生成doxygen样式模块描述 Sub ModuleDescription() ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "/**" ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "* @defgroup " ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "* @brief " ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "* " ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "* Detailed description." ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "* @{" ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "*/" ActiveDocument.Selection.NewLine() ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "/** @} */ " End Sub '生成doxygen样式类描述 Sub ClassDescription() Dim className Dim StartLine className = ActiveDocument.Selection.text 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, 0) ActiveDocument.Selection.EndOfLine() 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.text = "/**" ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "* @class " + className ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "* @brief " ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "* " ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "* Detailed description." ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "*/" End If End Sub '生成doxygen样式组描述 Sub GroupDescription() ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "/**" ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "* @name " ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "* @brief " ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "* " ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "* Detailed description." ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "* @{" ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "*/" ActiveDocument.Selection.NewLine() ActiveDocument.Selection.NewLine() ActiveDocument.Selection.text = "/** @} */" End Sub End Module
PS:
VS2008注释宏不能运行的解决办法
搜索 文件 vsmsvr.exe.config ( 默认C盘安装的路径为 C:\Program Files\Common Files\microsoft shared\VSA\9.0\VsaEnv)。。
打开这个文件在里面的runtime节点下增加 <AllowDComReflection enabled="1"/> 或<AllowDComReflection enabled="true"/> 一句,如下文件内容。。
<?xml version ="1.0"?> <configuration> <startup> <supportedRuntime version="v2.0.50727"/> </startup> <runtime> <AllowDComReflection enabled="1"/> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="EnvDTE" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/> <bindingRedirect oldVersion="7.0.3300.0" newVersion="8.0.0.0"/> </dependentAssembly> </assemblyBinding> </runtime> <system.net> <settings> <ipv6 enabled="true" /> </settings> </system.net> </configuration>
相关文章推荐
- VC下使用Macro (vbs)来实现标准函数注释的自动添加
- VC下使用Macro (vbs)来实现标准函数注释的自动添加
- 在VC2008下使用 Log4cxx 配置步骤说明:
- [C] c99int(让VC等编译器自动兼容C99的整数类型)V1.02。源码托管到github、添加CMake编译配置文件、使用doxygen规范注释
- 使用VAssistX为VS2008 c++代码添加函数头注释
- 在VC中添加响应自定义的消息的代码步骤
- windows下使用vc2008编译librtmp
- VC2008下使用OpenSSL 1.0.0g(免编译)
- 使用Aspose.Pdf在现有的PDF文件中添加注释
- 在VC中添加响应自定义的消息的代码步骤
- sharepoint 2013 部署步骤“添加解决方案”中出现错误: 已在此服务器场中安装 ID 为{guid}的功能。请使用强制属性显式地重新安装此功能。
- Eclipse开发项目,自动添加注释的使用
- 使用T4模板为EF框架添加数据库实体注释
- 使用Windows Storage Server 2008给hype-v添加iSCSI盘 推荐
- 使用VC++将程序添加到自启动项目中
- 使用VC2008 Express编写Win32控制台应用程序及其安装(初学者适用)
- VC使用“添加方法向导”添加调度映射方法“
- VC对话框如何添加WM_ERASEBKGND消息(OnEraseBkgnd函数)及对话框使用位图背景并透明
- VC 6.0 快捷键添加/取消注释
- 201402 系统更新后 VS2010 的宏功能不能正常使用(如添加头注释)