⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 csdn_文档中心_comment-uncomment selected code in visual c++.htm

📁 csdn10年中间经典帖子
💻 HTM
📖 第 1 页 / 共 3 页
字号:
      GetCommentStyle(strFileExt) If strCommentStyle = ““ Then If MsgBox(“This 
      macro can automatically comment selected text of files with the following 
      extentions:“ & vbCrLf & “.CPP, .H, .HPP, .DSM, .VBS, .JS;“ & _ 
      vbCrLf & “Press OK to specify a comment string for this “ & 
      strFileExt & “ file(“ & oActiveDoc.Name & “).“, vbInformation 
      + vbOKCancel, “AutoComment“) = vbCancel Then Exit Function Else 
      strCommentStyle = Trim(InputBox(“Please type in a comment string in the 
      text box below; default is ‘//‘.“, “Specify a Comment String“, “//“)) If 
      strCommentStyle = ““ Then Exit Function End If End If Call 
      CommentSelection2(oActiveDoc.Selection, strCommentStyle, bComment) 
      CommentDocument = True End Function Function CommentSelection(oTextSel, 
      strCommentStyle, ByVal bComment) Dim i Dim strTemp, strTextSel Dim 
      nTopLine, nBottomLine Dim nCurrentColumn, nCurrentLine nTopLine = 
      oTextSel.TopLine nBottomLine = oTextSel.BottomLine nCurrentLine = 
      oTextSel.CurrentLine nCurrentColumn = oTextSel.CurrentColumn For i = 
      nTopLine To nBottomLine oTextSel.GoToLine i, 1 strTextSel = oTextSel.Text 
      If bComment Then strTemp = CommentOneLine(strTextSel, strCommentStyle) 
      Else strTemp = UnCommentOneLine(strTextSel, strCommentStyle) End If 
      oTextSel.Text = strTemp Next If nCurrentLine = nTopLine Then 
      oTextSel.MoveTo nBottomLine, 0 oTextSel.MoveTo nTopLine, 1, dsExtend Else 
      oTextSel.MoveTo nTopLine, 1 oTextSel.MoveTo nBottomLine + 1, 1, dsExtend 
      End If CommentSelection = Abs(nBottomLine - nTopLine) + 1 End Function 
      Function CommentSelection2(oTextSel, strCommentStyle, bComment) Dim i, 
      strTemp, strTextSel Dim oArray, nUBound Dim nTopLine, nBottomLine Dim 
      nCurrentColumn, nCurrentLine nTopLine = oTextSel.TopLine nBottomLine = 
      oTextSel.BottomLine nCurrentLine = oTextSel.CurrentLine nCurrentColumn = 
      oTextSel.CurrentColumn oTextSel.GoToLine nTopLine oTextSel.MoveTo 
      nBottomLine, 0, dsExtend oArray = Split(oTextSel, vbCrLf) strTextSel = ““ 
      nUBound = UBound(oArray) For i = 0 To nUBound strTemp = oArray(i) If i 
      <> nUBound Then If bComment Then strTextSel = strTextSel & 
      CommentOneLine(strTemp, strCommentStyle) & vbCrLf Else strTextSel = 
      strTextSel & UnCommentOneLine(strTemp, strCommentStyle) & vbCrLf 
      End If Else If bComment Then strTextSel = strTextSel & 
      CommentOneLine(strTemp, strCommentStyle) Else strTextSel = strTextSel 
      & UnCommentOneLine(strTemp, strCommentStyle) End If End If Next 
      oTextSel.Text = strTextSel If nCurrentLine = nTopLine Then oTextSel.MoveTo 
      nBottomLine, 0 oTextSel.MoveTo nTopLine, 1, dsExtend Else oTextSel.MoveTo 
      nTopLine, 1 oTextSel.MoveTo nBottomLine + 1, 1, dsExtend End If 
      CommentSelection2 = Abs(nBottomLine - nTopLine) + 1 End Function Function 
      CommentOneLine(strLine, strCommentStyle) Dim nStrLen Dim i, char 
      CommentOneLine = strLine nStrLen = Len(strLine) If nStrLen = 0 Then Exit 
      Function For i = 1 To nStrLen char = Mid(strLine, i, 1) If char <> “ 
      “ And char <> vbTab And char <> vbCr And char <> vbLf 
      Then Exit For End If Next If i > 1 And i <= nStrLen Then 
      CommentOneLine = Left(strLine, i - 1) & strCommentStyle & 
      Mid(strLine, i) ElseIf i = 1 Then CommentOneLine = strCommentStyle & 
      strLine End If End Function Function UnCommentOneLine(strLine, 
      strCommentStyle) Dim nStrLen Dim i, char UnCommentOneLine = ““ nStrLen = 
      Len(strLine) If nStrLen = 0 Then Exit Function For i = 1 To nStrLen char = 
      Mid(strLine, i, 1) If char <> “ “ And char <> vbTab Then Exit 
      For End If Next If Mid(strLine, i, Len(strCommentStyle)) = strCommentStyle 
      Then If i > 1 Then UnCommentOneLine = Left(strLine, i - 1) & 
      Mid(strLine, i + Len(strCommentStyle)) ElseIf i = 1 Then UnCommentOneLine 
      = Mid(strLine, Len(strCommentStyle) + 1) End If Else UnCommentOneLine = 
      strLine End If End Function ‘------------------------------------------ 
      ‘Returns document type in uppercase letters ‘ or returns ““ if oDoc is not 
      a valid ‘ object or oDoc just has no extension 
      ‘------------------------------------------ Function GetDocType(oDoc) Dim 
      strFileName Dim strTemp Dim nPos GetDocType = ““ If oDoc Is Nothing Then 
      Exit Function strFileName = oDoc.Name nPos = InStrRev(strFileName, “.“) If 
      nPos > 0 Then GetDocType = UCase(Mid(strFileName, nPos)) End Function 
      Function IsBlank(strLine) Dim char Dim i, nStrLen nStrLen = Len(strLine) 
      IsBlank = True For i = 1 To nStrLen char = Mid(strLine, i, 1) If char 
      <> “ “ And char <> vbTab Then IsBlank = False Exit For End If 
      Next End Function Function GetCommentStyle(strFileExt) Select Case 
      strFileExt Case “.CPP“, “*.CXX“ GetCommentStyle = “//“ Case “.H“, “.HPP“ 
      GetCommentStyle = “//“ Case “.JS“ GetCommentStyle = “//“ Case “.IDL“ 
      GetCommentStyle = “//“ Case “.DSM“ GetCommentStyle = “‘“ Case “.VBS“ 
      GetCommentStyle = “‘“ Case Else GetCommentStyle = ““ End Select End 
      Function <BR></TD></TR></TBODY></TABLE>
<TABLE align=center bgColor=#666666 border=0 cellPadding=2 cellSpacing=1 
width=770>
  <TBODY>
  <TR>
    <TD bgColor=#cccccc colSpan=3><SPAN style="COLOR: #cccccc"><IMG height=16 
      hspace=1 
      src="CSDN_文档中心_Comment-Uncomment selected code in Visual C++.files/ico_pencil.gif" 
      width=16> </SPAN>&nbsp;&nbsp;&nbsp;&nbsp; george2000 <I>(2000-9-11 
      10:27:31)</I> </TD></TR>
  <TR>
    <TD bgColor=#ffffff colSpan=3 width=532><BR>At first, I give my thanks to 
      youngke.It is my experience to share with you. In the definition of the 
      CommentCode command, we can use the following code to implement our 
      functions such as commenting the selected codes. STDMETHODIMP 
      CCommands::CommentCode() { AFX_MANAGE_STATE(AfxGetStaticModuleState()); // 
      TODO: Replace this with the actual code to execute this command // Use 
      m_pApplication to access the Developer Studio Application object, // and 
      VERIFY_OK to see error strings in DEBUG builds of your add-in // (see 
      stdafx.h) ITextSelection *pTextSelection; GetTextSelection( 
      m_pApplication, &amp;pTextSelection); CommentSelectedCode( 
      pTextSelection); return S_OK; } The UncommentCode is just like so. Good 
      luck with you and your study! <BR></TD></TR></TBODY></TABLE>
<TABLE align=center bgColor=#666666 border=0 cellPadding=2 cellSpacing=1 
width=770>
  <TBODY>
  <TR>
    <TD bgColor=#cccccc colSpan=3><SPAN style="COLOR: #cccccc"><IMG height=16 
      hspace=1 
      src="CSDN_文档中心_Comment-Uncomment selected code in Visual C++.files/ico_pencil.gif" 
      width=16> </SPAN>&nbsp;&nbsp;&nbsp;&nbsp; RedFire <I>(2000-9-8 
      13:47:37)</I> </TD></TR>
  <TR>
    <TD bgColor=#ffffff colSpan=3 width=532><BR>jx_wq,我认为还是多了解一些比较好! 
  <BR></TD></TR></TBODY></TABLE>
<TABLE align=center bgColor=#666666 border=0 cellPadding=2 cellSpacing=1 
width=770>
  <TBODY>
  <TR>
    <TD bgColor=#cccccc colSpan=3><SPAN style="COLOR: #cccccc"><IMG height=16 
      hspace=1 
      src="CSDN_文档中心_Comment-Uncomment selected code in Visual C++.files/ico_pencil.gif" 
      width=16> </SPAN>&nbsp;&nbsp;&nbsp;&nbsp; RedFire <I>(2000-9-8 
      13:46:44)</I> </TD></TR>
  <TR>
    <TD bgColor=#ffffff colSpan=3 width=532><BR>jx_wq,我认为还是多了解一些比较好! 
  <BR></TD></TR></TBODY></TABLE>
<TABLE align=center bgColor=#666666 border=0 cellPadding=2 cellSpacing=1 
width=770>
  <TBODY>
  <TR>
    <TD bgColor=#cccccc colSpan=3><SPAN style="COLOR: #cccccc"><IMG height=16 
      hspace=1 
      src="CSDN_文档中心_Comment-Uncomment selected code in Visual C++.files/ico_pencil.gif" 
      width=16> </SPAN>&nbsp;&nbsp;&nbsp;&nbsp; jx__wq <I>(2000-9-8 
      12:43:00)</I> </TD></TR>
  <TR>
    <TD bgColor=#ffffff colSpan=3 
      width=532><BR>有那么费劲么,VC开发环境提供自已编写宏(用VBScript)的功能,用这个功能,只须一句话即可实现注释选定的代码块的功能,look: 
      ActiveDocument.Selection = “/*“ + ActiveDocument.Selection + “*/“ 
      至于取消注释,也可以很轻松地实现。 <BR></TD></TR></TBODY></TABLE><BR>
<DIV align=center>
<TABLE align=center bgColor=#cccccc border=0 cellPadding=2 cellSpacing=1 
width=770>
  <TBODY>
  <TR>
    <TH bgColor=#006699 id=white><FONT 
color=#ffffff>我要评论</FONT></TH></TR></TBODY></TABLE></DIV>
<DIV align=center>
<TABLE border=0 width=770>
  <TBODY>
  <TR>
    <TD>你没有登陆,无法发表评论。 请先<A 
      href="http://www.csdn.net/member/login.asp?from=/Develop/read_article.asp?id=578">登陆</A> 
      <A 
href="http://www.csdn.net/expert/zc.asp">我要注册</A><BR></TD></TR></TBODY></TABLE></DIV><BR>
<HR noShade SIZE=1 width=770>

<TABLE border=0 cellPadding=0 cellSpacing=0 width=500>
  <TBODY>
  <TR align=middle>
    <TD height=10 vAlign=bottom><A 
      href="http://www.csdn.net/intro/intro.asp?id=2">网站简介</A> - <A 
      href="http://www.csdn.net/intro/intro.asp?id=5">广告服务</A> - <A 
      href="http://www.csdn.net/map/map.shtm">网站地图</A> - <A 
      href="http://www.csdn.net/help/help.asp">帮助信息</A> - <A 
      href="http://www.csdn.net/intro/intro.asp?id=2">联系方式</A> - <A 
      href="http://www.csdn.net/english">English</A> </TD>
    <TD align=middle rowSpan=3><A 
      href="http://www.hd315.gov.cn/beian/view.asp?bianhao=010202001032100010"><IMG 
      border=0 height=48 
      src="CSDN_文档中心_Comment-Uncomment selected code in Visual C++.files/biaoshi.gif" 
      width=40></A></TD></TR>
  <TR align=middle>
    <TD vAlign=top>百联美达美公司 版权所有 京ICP证020026号</TD></TR>
  <TR align=middle>
    <TD vAlign=top><FONT face=Verdana>Copyright &copy; CSDN.net, Inc. All rights 
      reserved</FONT></TD></TR>
  <TR>
    <TD height=15></TD>
    <TD></TD></TR></TBODY></TABLE></DIV>
<DIV></DIV><!--内容结束//--><!--结束//--></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -