首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> C語言 >> VC >> VC 教學

VC6.0 利用巨集自動產生檔案標頭註解

     編輯:VC 教學

需求:統一專案檔案標頭格式

IDE 如 Eclipse、Dev-C++ 內建檔案範本支援變數替換,VC6.0 雖無內建功能,但可透過巨集錄製達成同樣效果。

目標格式

/**
 * Name:
 * Copyright:
 * Author:
 * Date: 2008-4-18 21:54:32
 * Description:
 * Modification:
 **/

操作步驟

  1. 選單 Tools → Macro,彈出對話框。
  2. 點選 Record,輸入巨集名稱 FILECOMMENT。
  3. 依序輸入上述註解內容 (含換行),完成後停止錄製。
  4. 點選 Edit 查看/修改產生的 VBA 程式碼。
  5. 選單 Options → Keystrokes,指定快速鍵 Ctrl+E。

巨集程式碼 (可直接貼上修改)


Sub FILECOMMENT()
'DESCRIPTION: COMMENT For file version
ActiveDocument.Selection = "/**"
ActiveDocument.Selection.NewLine
ActiveDocument.Selection = " * Name: "
ActiveDocument.Selection.NewLine
ActiveDocument.Selection = " * Copyright: "
ActiveDocument.Selection.NewLine
ActiveDocument.Selection = " * Author: "
ActiveDocument.Selection.NewLine
ActiveDocument.Selection = " * Date: "
ActiveDocument.Selection = Date + " " + Time  ' 自動插入當前日期時間
ActiveDocument.Selection.NewLine
ActiveDocument.Selection = " * Description: "
ActiveDocument.Selection.NewLine
ActiveDocument.Selection = " * Modification: "
ActiveDocument.Selection.NewLine
ActiveDocument.Selection = " **/"
End Sub

進階擴充建議

  • 加入 ActiveDocument.Selection = " * File: " + ActiveDocument.Name 自動帶入檔名。
  • 搭配 InputBox 讓使用者輸入作者、版權等資訊。
  • 若專案使用原始碼控制,可整合關鍵字展開 ($Author$, $Date$)。

自此,新建檔案按 Ctrl+E 即可插入標準註解,提升團隊程式碼規範一致性。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved