cout << "Hello World!" << endl; // 张鲁夺 :: 个人博客,幸福着你的幸福!


一个非常好用的VC++ 6.0注释宏

作者:转载,2018年1月14日

出处:互联网


在当下,不知道还有谁和我一样,还是主要使用Vc++ 6.0做为主要开发工具?前两天重装系统时,弄丢了一个用了N年的用于在VC6编辑器中的注释宏。今从互联网上找到,贴于此以备再次弄丢。

	Sub Comment()

		If Documents.Count = 0 Then

		Exit Sub
		End If

		lTopLine     = ActiveDocument.Selection.TopLine
		lBottomLine  = ActiveDocument.Selection.BottomLine
		lInsertPoint = ActiveDocument.Selection.CurrentLine

		For I = lTopLine To lBottomLine
			ActiveDocument.Selection.MoveTo I, 1
			ActiveDocument.Selection.SelectLine
			s                             = ActiveDocument.Selection.Text

			If s <> vbCrLf Then
				s                            = "//" + vbTab + s
			End If

			ActiveDocument.Selection.Text = s
		Next

		If lTopLine = lInsertPoint Then
			ActiveDocument.Selection.MoveTo lBottomLine, dsEndOfLine
			ActiveDocument.Selection.MoveTo lTopLine, 1, dsExtend
		Else
			ActiveDocument.Selection.MoveTo lTopLine, 1
			ActiveDocument.Selection.MoveTo lBottomLine, dsEndOfLine, dsExtend
		End If

	End Sub

	'多行反注释

	Sub Uncomment()

		If Documents.Count = 0 Then

		Exit Sub
		End If

		lTopLine     = ActiveDocument.Selection.TopLine
		lBottomLine  = ActiveDocument.Selection.BottomLine
		lInsertPoint = ActiveDocument.Selection.CurrentLine

		For I = lTopLine To lBottomLine
			ActiveDocument.Selection.MoveTo I, 1
			ActiveDocument.Selection.SelectLine
			s = ActiveDocument.Selection.Text
			While Left(s, 1) = " " Or Left(s, 1) = vbTab
			s = Right(s, Len(s) - 1)
			Wend

			If Left(s, 3) = "//" + vbTab Then
				s = Right(s, Len(s) - 3)
			ElseIf Left(s, 2) = "//" Then
				s = Right(s, Len(s) - 2)
			End If

			ActiveDocument.Selection.Text = s
		Next

		If lTopLine = lInsertPoint Then
			ActiveDocument.Selection.MoveTo lBottomLine, dsEndOfLine
			ActiveDocument.Selection.MoveTo lTopLine, 1, dsExtend
		Else
			ActiveDocument.Selection.MoveTo lTopLine, 1
			ActiveDocument.Selection.MoveTo lBottomLine, dsEndOfLine, dsExtend
		End If

		ActiveDocument.Selection.SmartFormat
	End Sub


Copyright © 2015 Zhang Luduo.

All rights reserved.