Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Visual Studio.NET / General / July 2007

Tip: Looking for answers? Try searching our database.

C++ toggle between source and header files

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jim Brown - 30 Jul 2007 21:52 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.

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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.