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的朋友。

解决方案 »

  1.   

    这是另一个版本,各有优缺点,您看着用吧;-)
    '------------------------------------------------------------------------------
    ' 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