文章出处:http://www.alteridem.net/2008/02/26/visual-studio-macro-to-switch-between-cpp-and-h-files/
1.选择VS工具(T)-->宏(M)
2.在新打开窗口右边项目列表,选择MyMacros --> 打开MyModule
3.粘贴下面代码
‘=====================================================================
‘ If the currently open document is a CPP or an H file, attempts to
‘ switch between the CPP and the H file.
‘=====================================================================
Public Sub SwitchBetweenSourceAndHeader()
Dim currentDocument As String
Dim targetDocument As String
currentDocument = ActiveDocument.FullName
If currentDocument.EndsWith(“.cpp”, StringComparison.InvariantCultureIgnoreCase) Then
targetDocument = Left(currentDocument, Len(currentDocument) - 3) + “h”
OpenDocument(targetDocument)
ElseIf currentDocument.EndsWith(“.h”, StringComparison.InvariantCultureIgnoreCase) Then
targetDocument = Left(currentDocument, Len(currentDocument) - 1) + “cpp”
OpenDocument(targetDocument)
End If
End Sub
‘=====================================================================
‘ Given a document name, attempts to activate it if it is already open,
‘ otherwise attempts to open it.
‘=====================================================================
Private Sub OpenDocument(ByRef documentName As String)
Dim document As EnvDTE.Document
Dim activatedTarget As Boolean
activatedTarget = False
For Each document In Application.Documents
If document.FullName = documentName And document.Windows.Count > 0 Then
document.Activate()
activatedTarget = True
Exit For
End If
Next
If Not activatedTarget Then
Application.Documents.Open(documentName, “Text”)
End If
End Sub
4.在MyMacros右键重命名(个人喜好,可改可不改)-->CppUtilities
5.在MyMacros右键生成。
6.回到VS2008,选择工具(T)-->选项(O)
7.在"显示命令包含"输入刚才生成的宏的名字"CppUtilities"
8.在"按快捷键(P)"按下快捷键(本人设定的是Alt+Q,看个人喜好)
9.确定。
10.去体验一下吧。