Eclipse、Dev-C++ 等 IDE 內建優秀的文件模板註釋功能,但 Visual C++ 6.0 卻缺乏現成的註釋插入機制。幸好 VC6 強大的巨集錄製功能能完美填補這一空白,讓我們能一鍵生成規範的文件頭註釋。
/**
* Name:
* Copyright:
* Author:
* Date: 2008-4-18 21:54:32
* Description:
* Modification:
**/
FILECOMMENT,依序輸入上述註釋內容(含換行),完成後停止錄製。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
DATE + TIME 會自動插入當前系統日期時間,無需手動修改。透過簡單的巨集錄製與編輯,VC6 瞬間擁有媲美現代 IDE 的文件註釋能力,統一團隊代碼風格、提升維護效率,且零成本、零插件、零學習曲線。建議將此技巧納入團隊開發規範手冊。