可以式式宏,就是vbscript写的脚本,vstudio有一整套对象模型支持宏的
我记不清了,大概是
activedocument.selection.xxxxxxxx是插入字符的方法,疾步请了,翻番msdn把

解决方案 »

  1.   

    网上有现成的宏,到www.codeguru.com上面找吧。
      

  2.   

    vc带有comment/uncomment 宏(有时会出错)
    曾经找到一个addin,有时也会出错,胆子大一点,还可以用
      

  3.   

    哈哈,我制作了这样一个宏,就解决了问题了
    Sub Comment()
        s=Replace(ActiveDocument.Selection,vbCrLf,vbCrLf+"//")
        s="//"+s
        If Len(s)>2 and Mid(s,Len(s)-1,2) = "//" Then
            s=Mid(s,1,Len(s)-2)
        End If
        ActiveDocument.Selection=s
    End Sub
    然后给这个宏定义一个快捷健不就行了
      

  4.   

    其实不需要宏的,可以用以下这种方法,我看微软有些示例代码就是这么搞的
    #if 0//你要注释的代码#endif //0
      

  5.   

    给drugplus加分呵呵,同时感谢sxbyl,duz等人
    http://codeguru.earthweb.com/devstudio_macros/comment_uncomment.shtml
    Sub CommentOut ()
    'DESCRIPTION: Comments out a selected block of text.
    Dim win
    set win = ActiveWindow
    if win.type <> "Text" Then
      MsgBox "This macro can only be run when a text editor window is active."
    else
    CommentType = "//" StartLine = ActiveDocument.Selection.TopLine
    EndLine = ActiveDocument.Selection.BottomLine
    If EndLine < StartLine Then
    Temp = StartLine
    StartLine = EndLine
    EndLine = Temp
    End If If EndLine = StartLine Then
    ActiveDocument.Selection = CommentType + ActiveDocument.Selection
    Else 
    For i = StartLine To EndLine
    ActiveDocument.Selection.GoToLine i
    ActiveDocument.Selection.SelectLine
    ActiveDocument.Selection = CommentType + _
    ActiveDocument.Selection
    Next
    End If
    End If
    End Sub
    Sub UnCommentOut ()
    'DESCRIPTION: Uncomments a selected block of text.
    Dim win
    set win = ActiveWindow
    if win.type <> "Text" Then
      MsgBox "This macro can only be run when a text editor window is active."
    else
    StartLine = ActiveDocument.Selection.TopLine
    EndLine = ActiveDocument.Selection.BottomLine
    If EndLine < StartLine Then
    Temp = StartLine
    StartLine = EndLine
    EndLine = Temp
    End If For i = StartLine To EndLine
    TmpBlock = "" ActiveDocument.Selection.GoToLine i
    ActiveDocument.Selection.SelectLine
    CmtBlock = ActiveDocument.Selection Trim(CmtBlock) If Instr(CmtBlock,"//") <> 0 Then 
    TmpBlock = TmpBlock + Left (CmtBlock, Instr (CmtBlock,"//") - 1)
    CmtBlock = Right(CmtBlock, (Len(CmtBlock) - (Instr(CmtBlock, "//") + 1)))
    CmtBlock = TmpBlock + CmtBlock
    End If ActiveDocument.Selection = CmtBlock
    Next End If
    End Sub