1. 程式人生 > >VS2010利用巨集快速添加註釋(函式描述,修改註釋等)

VS2010利用巨集快速添加註釋(函式描述,修改註釋等)

在敲程式碼的過程中類和函式都需要進行註釋,但總是一遍一遍的複製貼上覺得很是麻煩,終於找到了一個不錯的解決方法:使用巨集。

    所謂巨集,就是一些命令組織在一起,作為一個單獨命令完成一個特定任務。在日常的辦公環境中,不論是Office還是Foxmail以及我們所使用的VS甚至輸入法都具有巨集的功能。VS2010中的巨集,不僅可以錄製模組、還可以錄製類和程式碼檔案。通過設定編輯巨集,然後為設定好的巨集新增特定的快捷鍵,就可以在VS2010程式碼編輯器中任何位置非常方便的新增設定的註釋塊。實現過程如下:

    1、開啟“工具”→“巨集”→“巨集IDE”,進入以下介面,右擊“MyMacros”,新增模組

    命名模組:

    2、新增程式碼並儲存

    雙擊所新增的模組,進入編輯狀態,新增如下程式碼:

Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports EnvDTE90a
Imports EnvDTE100
Imports System.Diagnostics

Public Module FunctionNotes
    Sub DocumentFileHeader()

        Dim DocSel As EnvDTE.TextSelection
        DocSel = DTE.ActiveDocument.Selection
        DocSel.NewLine()
        DocSel.Text = "/************************************************"
        DocSel.NewLine()
        DocSel.Text = "* &name:"
        DocSel.NewLine()
        DocSel.Text = "* &function:"
        DocSel.NewLine()
        DocSel.Text = "* &param[in]:"
        DocSel.NewLine()
        DocSel.Text = "* &return:"
        DocSel.NewLine()
        DocSel.Text = "* &author:rk"
        DocSel.NewLine()
        DocSel.Text = "* &version:V1.0"
        DocSel.NewLine()
        DocSel.Text = "* &date:" + System.DateTime.Now.ToLongDateString
        DocSel.NewLine()
        DocSel.Text = "************************************************/"

    End Sub

End Module
注意:設定快捷鍵之前,最好先執行一下巨集,確定巨集的能正確執行後再新增快捷鍵,

可以在“工具”→“巨集”→“Macro資源管理器”中找到剛新增的FunctionNotes下的DocumentFileHeader,右鍵執行一下

看一看有沒有效果。

如果沒有效果,可能是這個原因:點選開啟連結

    3、設定快捷鍵

    開啟“工具”→“選項”,選擇“鍵盤”,進行如下設定

    4、效果

<span style="color:#009900;">/************************************************
* &name:
* &function:
* &param[in]:
* &return:
* &author:rk
* &version:V1.0
* &date:2016年1月5日 星期二
************************************************/</span>

這個只是一個比較簡單的巨集,用來交給大家如何使用,如果有興趣寫出功能更加強大的巨集,

以下程式碼大家可以參考:

Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports EnvDTE90a
Imports EnvDTE100
Imports System.Diagnostics

Public Module Module1
    Private Function Copyright()
        Copyright = CStr(Date.Today.Year) + "科技 All right reserved"
    End Function

    Private Function EMailAddress()
        EMailAddress = "[email protected]"
    End Function

    Private Function AuthorName()
        AuthorName = "rk"
    End Function

    Function ProductName()
        ProductName = ""
    End Function

    Private Function GenGUIDString() As String
        Dim sGUID As String
        sGUID = System.Guid.NewGuid.ToString()
        sGUID = UCase(sGUID.Replace("-", "_"))
        GenGUIDString = sGUID
    End Function

    Private Function FileString(ByVal filename As String) As String
        FileString = UCase(filename.Replace(".", "_"))
        UCase(Left(ActiveDocument.Name, Len(ActiveDocument.Name) - 2))
    End Function

    Sub HeaderFileTemplate()
        If ActiveDocument.Language = EnvDTE.Constants.dsCPP Then ' C++
            If UCase(Right(ActiveDocument.Name, 2)) = ".H" Then  '標頭檔案
                Dim sGUID = GenGUIDString()
                Dim sFile = FileString(ActiveDocument.Name)
                Dim lens = 0
                Dim strDesc = "/*******************************************************************************" + vbLf + _
                              "* 版權所有(C) " + Copyright() + vbLf + _
                              "* 檔名稱 : " + ActiveDocument.Name + vbLf + _
                              "* 當前版本 : " + "1.0.0.1" + vbLf + _
                              "* 作    者 : " + AuthorName() + " (" + EMailAddress() + ")" + vbLf + _
                              "* 設計日期 : " + FormatDateTime(Date.Today, 1) + vbLf + _
                              "* 內容摘要 : " + vbLf + _
                              "* 修改記錄 : " + vbLf + _
                              "* 日    期  版    本  修改人   修改摘要" + vbLf + vbLf + _
                              "********************************************************************************/" + vbLf + _
                              "" + vbLf + _
                              "/**********************************  標頭檔案 ************************************/" + vbLf + _
                              "" + vbLf + _
                             "/********************************** 常量和巨集 **********************************/" + vbLf + _
                              "" + vbLf + _
                              "/********************************** 資料型別 **********************************/" + vbLf + _
                              "" + vbLf + _
                              "/********************************** 函式宣告 **********************************/" + vbLf + _
                              "" + vbLf + _
                              "/********************************** 類定義 ***********************************/" + vbLf + _
                              "" + vbLf + _
                ActiveDocument.Selection.StartOfDocument(0)
                ActiveDocument.Selection.text() = strDesc
            End If
        End If
    End Sub
    Sub ImplFileTemplate()
        If ActiveDocument.Language = EnvDTE.Constants.dsCPP Then ' C++
            Dim format1 = UCase(Right(ActiveDocument.Name, 2))
            Dim format2 = UCase(Right(ActiveDocument.Name, 4))
            If format1 = ".C" Or format2 = ".CPP" Or format2 = ".CXX" Then  '實現檔案
                Dim Descr = "/*******************************************************************************" + vbLf + _
                              "* 版權所有(C) " + Copyright() + vbLf + _
                              "* 檔名稱 : " + ActiveDocument.Name + vbLf + _
                              "* 當前版本 : " + "1.0.0.1" + vbLf + _
                              "* 作    者 : " + AuthorName() + " (" + EMailAddress() + ")" + vbLf + _
                              "* 設計日期 : " + FormatDateTime(Date.Today, 1) + vbLf + _
                              "* 內容摘要 : " + vbLf + _
                              "* 修改記錄 : " + vbLf + _
                              "* 日    期  版    本  修改人   修改摘要" + vbLf + vbLf + _
                              "********************************************************************************/" + vbLf + _
                            "/**************************** 條件編譯選項和標頭檔案 ****************************/" + vbLf + _
                            "" + vbLf + _
                            "/********************************** 巨集、常量 **********************************/" + vbLf + _
                            "" + vbLf + _
                            "/********************************** 資料型別 **********************************/" + vbLf + _
                            "" + vbLf + _
                            "/************************************ 變數 ************************************/" + vbLf + _
                            "" + vbLf + _
                            "/********************************** 函式實現 **********************************/" + vbLf + _
                            "" + vbLf + _
                            "/*********************************** 類實現 ***********************************/" + vbLf + _
                            "" + vbLf

                ActiveDocument.Selection.StartOfDocument(0)
                ActiveDocument.Selection.text = Descr
            End If
        End If
    End Sub

    Dim ParamArr()
    Function StripTabs(ByVal MyStr)
        Do While InStr(MyStr, vbTab) <> 0
            MyStr = Right(MyStr, Len(MyStr) - InStr(MyStr, vbTab))
        Loop
        StripTabs = Trim(MyStr)
    End Function

    Sub FunctionDesc()
        Dim retTp
        Dim Reti

        If ActiveDocument.Language = EnvDTE.Constants.dsCPP Then ' C++
            Dim Header = Trim(ActiveDocument.Selection.text)

            'Get the function return type.
            If Header <> "" Then
                Reti = InStr(Header, " ")
                Dim Loc = InStr(Header, "(")
                If Reti < Loc Then
                    retTp = StripTabs(Left(Header, Reti))
                    Header = Right(Header, Len(Header) - Reti)
                End If

                'Get the function name.
                Loc = InStr(Header, "(") - 1
                Dim Loc2 = InStr(Header, ")")
                If Loc > 0 And Loc2 > 0 Then 'make sure there is a '(' and a ')'
                    Dim fcName = Left(Header, Loc)
                    Header = Right(Header, Len(Header) - Len(fcName))

                    'Do we have storage type on the return type?
                    Trim(fcName)
                    If InStr(fcName, " ") <> 0 Then
                        retTp = retTp + Left(fcName, InStr(fcName, " "))
                        fcName = Right(fcName, Len(fcName) - InStr(fcName, " "))
                    End If

                    'Get the function parameters.
                    Dim iPrm = 0
                    Dim iPrmA = 0
                    Dim prms = Header

                    'Count the number of parameters. 
                    Do While InStr(prms, ",") <> 0
                        iPrm = iPrm + 1
                        prms = Right(prms, Len(prms) - InStr(prms, ","))
                    Loop

                    'Store the parameter list in the array.
                    If iPrm > 0 Then  ' If multiple params.
                        iPrm = iPrm + 1
                        iPrmA = iPrm
                        ReDim ParamArr(iPrm)
                        Do While InStr(Header, ",") <> 0
                            ParamArr(iPrm) = Left(Header, InStr(Header, ",") - 1)
                            'Remove brace from first parameter.
                            If InStr(ParamArr(iPrm), " (") <> 0 Then
                                ParamArr(iPrm) = Right(ParamArr(iPrm), _
                                  Len(ParamArr(iPrm)) - InStr(ParamArr(iPrm), " ("))
                                Trim(ParamArr(iPrm))
                            End If
                            Header = Right(Header, Len(Header) - InStr(Header, ","))
                            iPrm = iPrm - 1
                        Loop
                        ParamArr(iPrm) = Header
                        'Remove trailing brace from last parameter.
                        If InStr(ParamArr(iPrm), ")") <> 0 Then
                            ParamArr(iPrm) = Left(ParamArr(iPrm), _
                              InStr(ParamArr(iPrm), ")") - 1)
                            Trim(ParamArr(iPrm))
                        End If
                    Else 'Possibly one param.
                        ReDim ParamArr(1)
                        Header = Right(Header, Len(Header) - 1) ' Strip the first brace.
                        Trim(Header)
                        ParamArr(1) = StripTabs(Header)
                        If InStr(ParamArr(1), ")") <> 1 Then
                            ParamArr(1) = Left(ParamArr(1), InStr(ParamArr(1), ")") - 1)
                            Trim(ParamArr(1))
                            iPrmA = 1
                        End If
                    End If

                    'Position the cursor one line above the selected text.
                    ActiveDocument.Selection.LineUp()
                    ActiveDocument.Selection.LineDown()
                    ActiveDocument.Selection.StartOfLine()
                    'ActiveDocument.Selection = vbLf

                    Dim Descr = "/*******************************************************************************" + vbLf + _
                            "* 函式名稱 : " + fcName + vbLf + _
                      "* 功能描述 : "

                    'Print the parameter list. 
                    Dim Last = iPrmA
                    Do While iPrmA <> 0
                        'Remove a line feed from any of the arguments.
                        If InStr(ParamArr(iPrmA), vbLf) <> 0 Then
                            ParamArr(iPrmA) = Right(ParamArr(iPrmA), _
                              (Len(ParamArr(iPrmA)) - _
                              InStr(ParamArr(iPrmA), vbLf)))
                            Trim(ParamArr(iPrmA))
                        End If
                        ParamArr(iPrmA) = StripTabs(ParamArr(iPrmA))
                        'If there are 2+ parameters, the first parameter will 
                        'have a '(' prepended to it, remove it here:
                        If iPrmA = Last And Last <> 1 Then
                            ParamArr(iPrmA) = Right(ParamArr(iPrmA), _
                            Len(ParamArr(iPrmA)) - 1)
                        End If
                        Descr = Descr + vbLf + "* 參  數 : " + _
                          ParamArr(iPrmA)
                        iPrmA = iPrmA - 1
                    Loop
                    Descr = Descr + vbLf + _
                           "* 返 回 值 : " + retTp + vbLf + _
                        "* 作  者 : " + AuthorName() + vbLf + _
                        "* 設計日期 : " + FormatDateTime(Date.Today, 1) + vbLf + _
                           "* 修改日期     修改人    修改內容" + vbLf + _
                           "*******************************************************************************/" + vbLf
                    ActiveDocument.Selection.text = Descr
                End If
            End If
        End If
    End Sub

End Module


    。

相關推薦

VS2010利用巨集快速註釋函式描述修改註釋

在敲程式碼的過程中類和函式都需要進行註釋,但總是一遍一遍的複製貼上覺得很是麻煩,終於找到了一個不錯的解決方法:使用巨集。     所謂巨集,就是一些命令組織在一起,作為一個單獨命令完成一個特定任務。在日常的辦公環境中,不論是Office還是Foxmail以及我們所使用的

vs2010番茄助手快速註釋+快捷鍵

官網講解:http://www.wholetomato.com/products/features/vasnippets.asp 一個好的專案工程,註釋是必不可少的,vc助手中有一個功能可以幫助我們快捷添加註釋。設定方法如下:   1、點選Visual As

iOS UILable 文字圖片 文字前面中間後面

str nbsp tab 添加 tac nsa end agen mut 1,實例化一個UILable 2, // 創建一個富文本 NSMutableAttributedString *attri = [[NSMutableAttributedString

Linux監控自定義監控項配置郵件告警

map alt 服務端 網上 send rep pad ima 觸發 一、添加自定義監控項需求:監控某臺web的80端口連接數,並出圖。步驟:1):zabbix監控中心創建監控項目2):針對該監控項目以圖形展現第一步(需要到客戶端定義腳本)[root@zhuji ~]# v

快速排序C++實現遞迴非遞迴

#include <iostream> #include <vector> #include <stack> using namespace std; int q

MFC如何拷貝資源對話方塊工具欄

 MFC的資源機制是兩個檔案的配合,xxx.rc(xxx為專案名稱)檔案和resource.h檔案的配合,res.rc以指令碼的形式描述了資源的形式,如***對話方塊大小,ID,有什麼按鈕,按鈕的ID等等 如“關於”對話方塊在rc檔案內的描述(怎麼開啟,找到rc檔案,資源管

全面屏適配小米8三星s8

引入問題: 使用者提出自己的小米8手機執行app時候底部有黑邊,因為是內部系統不方便截圖,我這裡就從miui裡找了一個圖來代替 開始還擔心是螢幕適配的問題(dimens適配),但是系統中只適配橫向,縱向不做適配; 下次發版前給使用者的臨時處理方案: 設定-全面屏-應用全面屏執行設定

對PPT的操作文字替換圖片插入

using System;using System.Collections.Generic;using System.IO;using System.Linq;using System.Text;using System.Threading.Tasks;using POWER

樹梅派Ubuntu mate 16.04 首次安裝配置中文輸入法顯示配置

1.樹梅派開機自動登入配置 我們希望能在跳過登陸介面,自動登陸後直接啟動程式,可以進行一下配置。 sudo vim /etc/lightdm/lightdm.conf 如果沒有v

使用ADO GetChunk/AppendChunk 資料庫存取二進位制檔案如程式圖象

 在設計資料庫的過程中,我們會經常要儲存一些圖形、長文字、多媒體(視訊、音訊檔案)等各種各樣的程式檔案,如果我們在資料庫中僅儲存這些檔案的路徑資訊,儘管這可以大大地減小資料庫的大小,但是由於檔案存在磁碟上,我們除了維護資料庫外還要維護檔案的路徑資訊,保持二者的一致,這對於我們

整理Glide方法使用含義毛玻璃效果實現圓角

現在專案中一般使用Glide進行圖片載入,於是找一下他的各個方法的使用,方便使用而已。 新增依賴: compile 'com.github.bumptech.glide:glide:3.7.0' 基本使用: Glide .with(

CentOS 掛載硬件設備U盤硬盤

epel etc usb umount fdisk命令 asn shm fix 不用 1、掛載fat或者fat32分區的U盤 如果是用VM安裝的linux,在vm裏掛載U盤有兩個前提: 第一,主機裏的service要啟動: 第二,U盤是連接到虛擬機,而不是主機,需要確認這

sqlitesql替換特殊字元換行tab鍵

換tab  sql語句: UPDATE table_name SET field_name=REPLACE(field_name,char(09),'') 但是 sqlite會報錯 在sqlite中 換tab 為x'09'所以sql為:  update  question_

Android Studio主題設定介面背景字型顏色

話不多說直接上鍊接吧~ http://color-themes.com/?view=index 下載想要的主題,開啟AS → File → Import Settings 然後重啟。如果想換就在Se

scrapy的一些容易忽視的點模擬登陸傳遞item

信息 pan pytho 完成 xtra author back book 多少 scrapy爬蟲註意事項 item數據只有最後一條 item字段傳遞後錯誤,混亂 對一個頁面要進行兩種或多種不同的解析 xpath中contains的使用 提取不在標簽內的文本內容 使用cs

eclipse 快速註釋時指定作者名

這個用的工具是eclipse 安裝好後首先找到eclipse.ini檔案,這個檔案一般都是和exe檔案同級。 開啟編輯最後新增一句: -Duser.name=Jason 這個Jason 就是我的英文名稱。 eclipse.ini這個檔案的全部內容如下(我有修改其

光貓手機自動激活系統-開發指南-004- OLTvlanADD- VLAN

手機 光貓 手機激活系統 -開發指南-004- olt添加vlan(add- vlan) ADD-VLAN::OLTID=10.124.202.199:CTAG::VLAN=2108,DESC=2108,VLANMODE=SINGLE,PORTLIST=NA-0-19-0|NA-0-20-0|

快速事件監聽器到管理器

target getchild 支持 var 第一個 事件監聽 事件監聽器 spa () cc.eventManager.addListener({ event: cc.EventListener.TOUCH_ALL_AT_ONCE, onT

快速一個簡單的數據庫

快速 auto 建表 ima itl 技術分享 code -1 logs //示例建表 create table msg ( id int auto_increment primary key, title varchar(200), content varchar(2

Mac OS X中Launchpad的圖標刪除方法方法別試了和Linux很大區別

com nsh usr folders 單純 ron bsp blank 結構 說明:在Mac下的Launchpad圖標添加和刪除都與應用程序的app文件有關,如果單純的只想在Launchpad添加自定義的圖標,然後指定要某條命令運行時,建議不要這麽幹,Launchpad的