Sunday, 27 April 2008

How to switch between .H and .CPP files in visual studio.

I've written a macro for this, since I don't know any existing commands in VS.

Sub SwitchBetweenHeaderAndSource()
Dim oldFile As String
Dim newFile As String
oldFile = DTE.ActiveDocument.FullName
If (oldFile.EndsWith(".cpp")) Then
newFile = oldFile.Replace(".cpp", ".h")
If (oldFile.EndsWith(".h")) Then
newFile = oldFile.Replace(".h", ".cpp")
newFile = oldFile
End If
End If
Dim pi As EnvDTE.ProjectItem
pi = DTE.Solution.FindProjectItem(newFile)
If (Not pi Is Nothing) Then
End If
End Sub

You can write this macro in macro explorer, which you can find in Tools->Macros menu.
To assign a keyboard shortcut, you can go to Tools->Customize and click the Keyboard button. On that window you can find the macro and assign it a keyboard shortcut. I'm using Ctrl+"

No comments: