用vba写的自动添加源文件的宏,可以用来方便添加c++源文件的头注释

来源:互联网 发布:传奇霸业最新魂珠数据 编辑:程序博客网 时间:2024/05/15 06:38

Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports System.Diagnostics

Public Module Module1

    Public Sub AddClassComment()

        '定义选择区域

        Dim DocSel As EnvDTE.TextSelection

        Dim tmpStrArr As String()

        '初始化选择区域是当前文档的选择

        DocSel = DTE.ActiveDocument.Selection

        '选择区域移动到文档的开头

        DocSel.StartOfDocument()

        DocSel.Text = "/*******************************************************************"

        DocSel.NewLine()

        DocSel.Text = "* Copyright (C) abc Corporation"

        DocSel.NewLine()

        DocSel.Text = "* All rights reserved."

        DocSel.NewLine()

        DocSel.Text = "*"

        DocSel.NewLine()

        DocSel.Text = "*Author:   zmy (zmy12006@hotmail.com)"

        DocSel.NewLine()

        DocSel.Text = "*Create Date:" + DateTime.Now.ToString()

        DocSel.NewLine()

        DocSel.Text = "*FileName:" + DTE.ActiveDocument.Name

        DocSel.NewLine()

        DocSel.Text = "*Description:"

        DocSel.NewLine()

        DocSel.Text = "*"

        DocSel.NewLine()

        DocSel.Text = "* Date               Author         Description"

        DocSel.NewLine()

        DocSel.Text = "*" + DateTime.Now.ToString() + "       zmy" + "        Added"

        DocSel.NewLine()

        DocSel.Text = "*******************************************************************/"

        'Extend function

        tmpStrArr = DTE.ActiveDocument.Name.Split(".".ToCharArray())
        If tmpStrArr.Length = 2 Then
            If tmpStrArr(1).ToLower() = "h" Then
                DocSel.NewLine()
                DocSel.Text = "#ifndef  " + tmpStrArr(0).ToUpper() + "_" + tmpStrArr(1).ToUpper() + "_"
                DocSel.NewLine()
                DocSel.Text = "#define  " + tmpStrArr(0).ToUpper() + "_" + tmpStrArr(1).ToUpper() + "_"
                DocSel.NewLine()
                DocSel.NewLine()
                DocSel.NewLine()
                DocSel.NewLine()
                DocSel.Text = "#endif   //" + tmpStrArr(0).ToUpper() + "_" + tmpStrArr(1).ToUpper() + "_"
            ElseIf tmpStrArr(1).ToLower() = "cpp" Then
                DocSel.NewLine()
                DocSel.Text = "#include""" + tmpStrArr(0) + ".h"""
                DocSel.NewLine()
            End If
        End If


        DocSel.NewLine()

    End Sub
End Module

原创粉丝点击