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

📄 vcbible.dsm

📁 主要介绍vc++6.0的编程过程
💻 DSM
字号:
'File Description: VCBIBLE.DSM includes macros used in the book Visual C++ for Dummies

Sub AddNewFileToProject()
'DESCRIPTION: Add a new file to a project with comments.


'Begin Recording
	ExecuteCommand "FileNewInProject"
	ActiveDocument.Selection = "// File:   " & ActiveDocument.Name
	ActiveDocument.Selection.NewLine
	ActiveDocument.Selection = "// Author: Garrett Pease"
	ActiveDocument.Selection.NewLine
	ActiveDocument.Selection = "// Date:   " & Now
	ActiveDocument.Selection.NewLine
	ActiveDocument.Save
'End Recording

End Sub

Sub CreateFunctionDescriptionFile()
'DESCRIPTION: This function copies the function declarations 
' from a C/C++ file to an HTML file and creates a description 
' of the function.

'Create an HTML file for storing the information about a function
	CurrentSourceFileName = ActiveDocument.FullName
	TempString = CurrentSourceFileName
	Position = InStrRev(TempString,".")
    CurrentHTMLFileName = Left(TempString, Position) + "html"
	
	Documents.Add "Text"
	ActiveDocument.Save CurrentHTMLFileName
	ActiveDocument.Language = "HTML - IE 3.0"

'Create header for HTML File
	ActiveDocument.Selection = "<HTML>"
	ActiveDocument.Selection.NewLine
	ActiveDocument.Selection = "<HEAD>"
	ActiveDocument.Selection.NewLine
	ActiveDocument.Selection = "<TITLE>" & ActiveDocument.Name & "</TITLE>"
	ActiveDocument.Selection.NewLine
	ActiveDocument.Selection = "</HEAD>"
	ActiveDocument.Selection.NewLine
	ActiveDocument.Selection = "<BODY>"
	ActiveDocument.Selection.NewLine

'Document the first function and get its line number
	Documents(CurrentSourceFileName).Active = True
	ActiveDocument.Selection.StartOfDocument
	ActiveDocument.Selection.FindText "{"
	'Copy the function declaration
	LineNumber = ActiveDocument.Selection.CurrentLine
	ActiveDocument.Selection.LineUp
	ActiveDocument.Selection.EndOfLine dsExtend
	FunctionText = ActiveDocument.Selection.Text

	'Copy the function declaration to the HTML file
	' and create a description of the function
	Documents(CurrentHTMLFileName).Active = True
	ActiveDocument.Selection.NewLine
	OutputDescription FunctionText
	ActiveDocument.Selection.NewLine

'Move to the end of the first function and search the 
' rest of the source document for functions making sure
' not to document the first function again.
	Documents(CurrentSourceFileName).Active = True
	ActiveDocument.Selection.LineDown
	ExecuteCommand "GoToMatchBrace"
	ActiveDocument.Selection.LineDown
	While (ActiveDocument.Selection.FindText("{") = True _
	   And ActiveDocument.Selection.CurrentLine > LineNumber)
		'Copy the function declaration
		ActiveDocument.Selection.LineUp
		ActiveDocument.Selection.EndOfLine dsExtend
		FunctionText = ActiveDocument.Selection.Text

		'Copy the function declaration to the HTML file
		' and create a description of the function
		Documents(CurrentHTMLFileName).Active = True
		OutputDescription FunctionText
		ActiveDocument.Selection.NewLine

		'return to the source file and move to the end
		' of the function.
		Documents(CurrentSourceFileName).Active = True
		ActiveDocument.Selection.LineDown
		ExecuteCommand "GoToMatchBrace"
		ActiveDocument.Selection.LineDown
    Wend

'Create end of HTML File and close
	Documents(CurrentHTMLFileName).Active = True
	ActiveDocument.Selection = "</BODY></HTML>"
	ActiveDocument.Selection.NewLine
	ActiveDocument.Save

'Return 
End Sub


Dim ParamArr ()  ' Dynamic array to store function arguments.

'Strips the leading tab spaces. 
Function StripTabs (ByVal MyStr)
	Do While InStr(MyStr, vbTab) <> 0
		MyStr = Right(MyStr, Len(MyStr) - InStr(MyStr, vbTab)) 
	Loop 
	StripTabs = Trim(MyStr)
End Function

Sub OutputDescription(ByVal Description)
'DESCRIPTION: Create an HTML description of the function 
' passed in using the Description varaible. Based on 
' AddFunctionDescription macro in Microsofts Samples

	Header = StripTabs(Trim(Description))

	'Get the function return type.
	if Header <> "" then
		Reti = InStr(Header, " ")
		Loc = InStr(Header, "(")
		if Reti < Loc Then
		  RetTp = Left(Header, Reti)
		  Header = Right(Header, Len(Header) - Reti)
		End If

		'Get the function name.
		Loc = InStr(Header, "(") - 1
		Loc2 = InStr(Header, ")")
		if Loc > 0 And Loc2 > 0 then 'make sure there is a '(' and a ')'
			fcName = Left(Header, Loc)
			Header = Right(Header, Len(Header) - Len(fcName))

			'Do we have storage type on the return type?
			Trim (fcName)
			If InStr(fcName," ") <> 0 Then
				retTp = retTp + Left(fcName,InStr (fcName," "))
				fcName = Right(fcName, Len(fcName) - InStr(fcName," "))
			End If

			'Get the function parameters.
			iPrm = 0
			iPrmA = 0
			prms = Header 

			'Count the number of parameters. 
			Do While InStr(prms, ",") <> 0
				iPrm = iPrm + 1
				prms = Right(prms, Len(prms) - InStr(prms, ",")) 
			Loop 
			
			'Store the parameter list in the array.
			If iPrm > 0 Then  ' If multiple params.
				iPrm = iPrm + 1
				iPrmA = iPrm
				Redim ParamArr(iPrm)
				Do While InStr(header, ",") <> 0
					ParamArr(iPrm) = Left(Header, InStr (Header, ",") - 1)
					'Remove brace from first parameter.
					If InStr(ParamArr(iPrm), " (") <> 0 Then
						ParamArr(iPrm) = Right(ParamArr(iPrm), _
								Len(ParamArr(iPrm))-InStr(ParamArr(iPrm)," ("))
						Trim(ParamArr(iPrm))
					End If
					Header = Right(Header, Len(Header) - InStr(Header,","))
					iPrm = iPrm - 1 
					Loop 
				ParamArr(iPrm) = Header 
				'Remove trailing brace from last parameter.
				If InStr(ParamArr(iPrm), ")") <> 0 Then
					ParamArr(iPrm) = Left(ParamArr(iPrm), _
							InStr(ParamArr(iPrm), ")") - 1)
					Trim(ParamArr(iPrm))
				End If
			Else 'Possibly one param.
				Redim ParamArr(1)
				Header = Right(Header, Len(Header) - 1) ' Strip the first brace.
				Trim(Header)
				ParamArr(1) = StripTabs(Header)
				If InStr(ParamArr(1), ")") <> 1 Then
					ParamArr(1) = Left(ParamArr(1), InStr(ParamArr(1), ")") - 1)
					Trim(ParamArr(1))
					iPrmA = 1
				End If
			End If

			'Position the cursor one line above the selected text.
			ActiveDocument.Selection.LineUp
			ActiveDocument.Selection.LineDown
			ActiveDocument.Selection.StartOfLine
			ActiveDocument.Selection = vbLf

			Descr = "<TR><TD><B>Function name</B></TD><TD>" + fcName + _
					"</TD></TR><TR><TD><B>Description</B>" + _ 
					"</TD></TR><TR><TD><B>Return type</B>" + _
					"</TD><TD>" + RetTp + "</TD></TR>"
			
			'Print the parameter list. 
			Last = iPrmA
			Do While iPrmA <> 0
				'Remove a line feed from any of the arguments.
				If InStr(ParamArr(iPrmA), vbLf) <> 0 Then
					ParamArr(iPrmA) = Right(ParamArr(iPrmA), _
							(Len(ParamArr(iPrmA)) - _
							InStr(ParamArr(iPrmA), vbLf)))
					Trim(ParamArr(iPrmA))
				End If
				ParamArr(iPrmA) = StripTabs(ParamArr(iPrmA))
				'If there are 2+ parameters, the first parameter will 
				'have a '(' prepended to it, remove it here:
				if iPrmA = Last AND Last <> 1 then
				  ParamArr(iPrmA) = Right(ParamArr(iPrmA), _
						Len(ParamArr(iPrmA)) - 1)
				End If
				Descr = Descr + "<TR><TD><B>Argument</B></TD>" + _
						"<TD>" + ParamArr(iPrmA) + "</TD></TR>"
				iPrmA = iPrmA - 1
			Loop
			ActiveDocument.Selection = "<TABLE>" + vbLF + _
			      "<TH COLSPAN=2><BIG>" + Description + _
				  "</BIG></TH>" + vbLF & Descr & "</TABLE><BR>" + vbLF
		Else
			MsgBox("It is possible that the function you are trying to"+_
					" work with has a syntax error.")
		End if
	End If
End Sub

⌨️ 快捷键说明

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