學習Visual C++開發實戰寶典之總結
1、在Visual C++6.0中選擇File/New指令,打開New頁籤;
2、在清單中選擇Macro File選項,在File編輯框中輸入檔案名稱(如Command),單擊OK按鈕建立宏檔案,彈出New Macro File(建立宏檔案)視窗;
3、在Description備注框中輸入宏檔案的描述資訊(如:為開發環境添加批量注釋或取消注釋),單擊OK按鈕建立宏檔案。此時,在代碼編輯器中将建立一個宏檔案視窗;
4、向宏檔案中添加兩個子過程,語言為VBScript;
'------------------------------------------------------------------------------
'FILE DESCRIPTION: 為開發環境添加批量注釋或取消注釋
'------------------------------------------------------------------------------
Sub SetSelNote()'Sun DESCRIPTION:過程SetSelNote用于将選中的文本轉換為注釋
dim CurWin'目前獲得的視窗
set CurWin = ActiveWindow
if CurWin.type<>"Text" Then'判斷目前視窗是否是文本視窗
MsgBox "目前視窗不是文本視窗"
else
NoteType = "//"
BeginLine = ActiveDocument.Selection.TopLine
EndLine = ActiveDocument.Selection.BottomLine
if EndLine<BeginLine then
Line = BeginLine
BeginLine = EndLine
EndLine = Line
else
for row = BeginLine To EndLine
ActiveDocument.Selection.GoToLine row
ActiveDocument.Selection.SelectLine'選中目前行
ActiveDocument.Selection = NoteType+ActiveDocument.Selection
Next
End if
End if
End Sub
Sub CancelSelNote()
dim CurWin'目前獲得的視窗
set CurWin = ActiveWindow
if CurWin.type<>"Text" Then'判斷目前視窗是否是文本視窗
MsgBox "目前視窗不是代碼視窗"
else
BeginLine = ActiveDocument.Selection.TopLine
EndLine = ActiveDocument.Selection.BottomLine
if EndLine<BeginLine then
Line = BeginLine
BeginLine = EndLine
EndLine = Line
else
for row = BeginLine To EndLine
ActiveDocument.Selection.GoToLine row
ActiveDocument.Selection.SelectLine'選中目前行
SelBlock = ActiveDocument.Selection
Trim(SelBlock)
pos = instr(SelBlock, "//")
if pos<>0 then
RightBlock = Right(SelBlock,Len(SelBlock)-2)
ActiveDocument.Selection = RightBlock
End if
Next
End if
End if
End Sub
5、儲存宏檔案。選擇Tools/Customize指令,打開Customize(自定義)對話框,選擇Add-ins and Macro File(附加項和宏檔案)頁籤;
6、單擊Browse(浏覽)按鈕,打開浏覽對話框,選擇之前建立的宏檔案,此時會發現它顯示在Add-ins and Macro File清單中;
7、切換到Commands頁籤,在Category(類别)組合框中選擇Macros選項,在右側的清單中會顯示目前宏檔案中定義的指令;
8、在Commands清單中選中宏指令,将其拖動到工具欄中,此時彈出Button Appearance視窗;
9、在Button Appearance視窗中選擇Image only單選按鈕,在Images群組框中為按鈕選擇圖示,單擊OK按鈕完成工具欄設定;
10、按照步驟7~9的方法将另一個宏指令添加到工具欄中;
OK,大功告成!