天天看点

在VC6.0开发环境中添加批量注释和取消注释

学习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,大功告成!