VC虽然提供了块注释/*...*/,但它不能嵌套,实际上使用不多。可是一行一行的加或去//又太麻烦。于是我写了一个宏,可以将你选中的行全部加上 // 或去掉 //。
方法:新建宏后编辑它(菜单项:Tools\Micro),拷上下面的代码,运行这个宏即可!
Tips: 如果在Micro\Options中给它指定到Toolbar上或指定一个快捷键,勇气来会更方便。(我就用<Shift+/>作为快捷键,手都不用挪。)==================================================================
'------------------------------------------------------------------------------
' Description: Comment or comment out the selected rows.
' Author: JokeSmith007
' Date: 2002-6-18
' Note: You can use, modify or release it freely, but please keep
' the copyright info above.
'------------------------------------------------------------------------------Sub Comment()
'DESCRIPTION: Add or remove "//" at the beginning of the selected rows. Dim StartLine, EndLine, i
StartLine = ActiveDocument.Selection.TopLine
EndLine = ActiveDocument.Selection.BottomLine
ActiveDocument.Selection.StartOfLine dsFirstColumn For i = StartLine To EndLine
ActiveDocument.Selection.GoToLine i, dsMove
ActiveDocument.Selection.StartOfLine dsFirstColumn
ActiveDocument.Selection.CharRight dsExtend, 2
If ActiveDocument.Selection.Text = "//" Then
' Remove //
ActiveDocument.Selection.Text =""
Else
' Add //
ActiveDocument.Selection.StartOfLine dsFirstColumn
ActiveDocument.Selection = "//"
End If
Next ' Reselect the selected line
ActiveDocument.Selection.GoToLine StartLine, dsMove
ActiveDocument.Selection.LineDown dsExtend, EndLine - StartLine +1
End Sub==========================================================================试一试!好就顶一下!也希望借此多交VC的朋友。
解决方案 »
- 被鄙视了,草
- 窗口收到什么消息,表示它已经被摧毁,可以UnregisterClass它的类了?
- 如何在写文件时捕获文件在磁盘上的物理地址
- 如何响应其他窗口的消息,比如按钮点击消息
- 两个子窗口如何传值呢?
- 对于一个同时存在不止一个子窗口的程序,如何才能保证某个指定的子窗口总是被第一优先的刷新呢?
- 当控件Disabled后,如何同时改变其控件背景色、字体颜色及字体大小,急急急~~~~
- 读串口的线程函数中如何调用主窗口的成员变量!
- 请教UDP服务器的问题
- 有谁熟悉SetWindowRgn函数
- 谁说《深入浅出MFC》好,我跟谁拼!恨死侯捷!
- 请问可不可以用数组做为一个函数的输入和返回参数?可以的话能不能给出个例子?
'------------------------------------------------------------------------------
' Description: Comment or comment out the selected rows.
' Author: JokeSmith007
' Date: 2002-6-18
' Note: You can use, modify or release it freely, but please keep
' the copyright info above.
'------------------------------------------------------------------------------Sub Comment()
'DESCRIPTION: Add or remove "//" at the beginning of the selected rows. Dim StartLine, EndLine, i, bAdd StartLine = ActiveDocument.Selection.TopLine
EndLine = ActiveDocument.Selection.BottomLine
ActiveDocument.Selection.GoToLine StartLine, dsMove
ActiveDocument.Selection.StartOfLine dsFirstColumn
ActiveDocument.Selection.CharRight dsExtend, 2
If ActiveDocument.Selection.Text = "//" Then
' Remove //
bAdd = False
Else
bAdd = True
End If For i = StartLine To EndLine
ActiveDocument.Selection.GoToLine i, dsMove ActiveDocument.Selection.StartOfLine dsFirstColumn
ActiveDocument.Selection.CharRight dsExtend, 2
If bAdd Then
' Add //
ActiveDocument.Selection.StartOfLine dsFirstColumn
ActiveDocument.Selection = "//"
Else
' Remove //
If ActiveDocument.Selection.Text = "//" Then
ActiveDocument.Selection.Text =""
End If
End If
Next ' Reselect the selected lines
ActiveDocument.Selection.GoToLine StartLine, dsMove
ActiveDocument.Selection.LineDown dsExtend, EndLine - StartLine +1
End Sub