Click here to Skip to main content
12,512,439 members (61,594 online)
Click here to Skip to main content

Tagged as

Stats

123K views
956 downloads
24 bookmarked
Posted

Switch between Header and CPP File for Visual Studio .NET

, , 3 Jun 2008 CPOL
Here are two methods that allow you to quickly switch between associated header and implementation files in Visual Studio .NET
��Option Strict Off

Option Explicit Off



Imports EnvDTE

Imports System.Diagnostics



Public Module Opac



    Function WalkProjectItemsAndOpen(ByRef items As ProjectItems, ByRef name As String) As Boolean

        Dim item As ProjectItem



        If ReferenceEquals(items, Nothing) Then

            Return False

        End If



        For Each item In items

            Dim sub_items As ProjectItems

            sub_items = item.SubProject

            If Not sub_items Is Nothing Then

                If WalkProjectItemsAndOpen(sub_itemsm, name) Then

                    Return True

                End If

            End If

            If item.Name = name Then

                'MsgBox("Found " + name + " in project " + items.ContainingProject.UniqueName)

                Dim op As ItemOperations

                op = DTE.ItemOperations

                op.OpenFile(item.FileNames(0), Constants.vsViewKindTextView)

                Return True

            End If

        Next

        Return False

    End Function



    Sub Swap_H_CPP()

        Dim proj As Project

        Dim doc As Document

        Dim name As String



        doc = DTE.ActiveDocument

        name = doc.Name



        If name.EndsWith(".h") Then

            name = name.Replace(".h", ".cpp")

        ElseIf name.EndsWith(".cpp") Then

            name = name.Replace(".cpp", ".h")

        End If





        For Each proj In DTE.Solution.Projects

            If WalkProjectItemsAndOpen(proj.ProjectItems, name) Then

                Exit Sub

            End If

        Next



        Beep()



    End Sub



End Module

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Authors

Pavel Sokolov
Web Developer
Russian Federation Russian Federation
C++ programmer.

Pierre Arnaud
Web Developer
Switzerland Switzerland

Pierre Arnaud got a Ph.D. in computer science at the Swiss Federal Institute of Technology; he currently works both as an independent contractor on hardware and software projects at OPaC bright ideas and as a senior software designer at EPSITEC.

Pierre was a key contributor to the Smaky computer, a real time, multitasking system based on the Motorola 680x0 processor family.

Now, Pierre works on his spare time for the Creative Docs .NET project: it is a vector based drawing and page layout software based on .NET and AGG.


You may also be interested in...

Pro
Pro
| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.160929.1 | Last Updated 3 Jun 2008
Article Copyright 2002 by Pavel Sokolov, Pierre Arnaud
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid