Hi,
A long, long time ago (but I can still remember) I had a macro that would
toggle between a C++ source file and its header file, and vice versa. It
would open the other file if it wasn't already open. I'm using VS 2005 now,
and wonder if this great feature is built in by now.
Thanks,
Jim
David Wilkinson - 31 Jul 2007 04:17 GMT
> Hi,
>
> A long, long time ago (but I can still remember) I had a macro that would
> toggle between a C++ source file and its header file, and vice versa. It
> would open the other file if it wasn't already open. I'm using VS 2005 now,
> and wonder if this great feature is built in by now.
Jim:
This is the one I use (which I modified myself from one I found on the
newsgroups, please excuse any poor Visual Basic usage):
Sub OpenH()
'DESCRIPTION: Opens the .cpp/.cxx or .h file for the current
document.
Dim ext
ext = ActiveDocument.FullName
If ext = "" Then
msgbox("Error, no active document")
Exit Sub
End If
Dim DocName
DocName = UCase(ext)
On Error Resume Next
Dim fn
If Right(DocName, 4) = ".CPP" Or Right(DocName, 4) = ".CXX" Then
fn = Left(DocName, Len(DocName) - 3) & "h"
Application.Documents.Open(fn)
ElseIf Right(DocName, 2) = ".H" Then
fn = Left(DocName, Len(DocName) - 1) & "cpp"
Application.Documents.Open(fn)
If Err.Number Then
fn = Left(DocName, Len(DocName) - 1) & "cxx"
Application.Documents.Open(fn)
End If
Else
MsgBox("Error, not a .cpp/.cxx or .h file")
End If
End Sub

Signature
David Wilkinson
Visual C++ MVP
Andrew McDonald - 31 Jul 2007 20:30 GMT
"Jim Brown" <noSpam@nowhere.net> wrote...
> A long, long time ago (but I can still remember) I had a macro that would
> toggle between a C++ source file and its header file, and vice versa. It
> would open the other file if it wasn't already open. I'm using VS 2005
> now, and wonder if this great feature is built in by now.
VS 2005 has "go to header" in the context menu if you right-click anywhere
in a .cpp file, but inexplicably there's no corresponding "go to source" in
a .h file!
If you press the "open file" toolbar button it opens in the same directory
as the file you're currently editing (though I think you might be able to
switch this off), which I occasionally use to jump to the .cpp.
--
Andy