469,658 Members | 1,862 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,658 developers. It's quick & easy.

Short-cut to switch between .h and .cpp file

Hi

Can anyone tell me what is the short-cut to switch between a .h and .cpp
file, thanks

Torben Laursen

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.786 / Virus Database: 532 - Release Date: 29/10/2004
Nov 17 '05 #1
18 1745

"Torben Laursen" <do*****@work.com> wrote in message
news:ex**************@TK2MSFTNGP14.phx.gbl...
Hi

Can anyone tell me what is the short-cut to switch between a .h and .cpp
file, thanks

Torben Laursen

Can you elaborate on what you mean by switch?
Are you referring to the view in the editor window in Visual Studio .NET, or
to something else?
If it's viewing the files in the editor window, using the tabs at the top is
the quickest way to switch (once both files have been opened).

--
Peter [MVP Visual Developer]
Jack of all trades, master of none.
Nov 17 '05 #2
Hi Peter van der Goes,
If it's viewing the files in the editor window, using the tabs at the
top is the quickest way to switch (once both files have been opened).


The quickest way is "Ctrl-TAB" (so I do not have to catch the mouse...)

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
Nov 17 '05 #3

"Jochen Kalmbach" <no********************@holzma.de> wrote in message
news:Xn*********************************@127.0.0.1 ...
Hi Peter van der Goes,
If it's viewing the files in the editor window, using the tabs at the
top is the quickest way to switch (once both files have been opened).


The quickest way is "Ctrl-TAB" (so I do not have to catch the mouse...)

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/


Thanks, Jochen. You're correct of course, with one caveat.
If I have 6 or 7 source code files open in the editor, ctrl-tab seems to
switch between files in the order they were opened, not necessarily in the
desired order.

--
Peter [MVP Visual Developer]
Jack of all trades, master of none.
Nov 17 '05 #4
Hi Peter van der Goes,
Thanks, Jochen. You're correct of course, with one caveat.
If I have 6 or 7 source code files open in the editor, ctrl-tab seems
to switch between files in the order they were opened, not necessarily
in the desired order.


No, it switches in the order, which was last used!

If you need to switch between two files, you *only* need to select the
second file once and then one Ctrl-TAB will switch between these two files.

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
Nov 17 '05 #5
Jochen Kalmbach wrote:

Hi Peter van der Goes,
Thanks, Jochen. You're correct of course, with one caveat.
If I have 6 or 7 source code files open in the editor, ctrl-tab seems
to switch between files in the order they were opened, not necessarily
in the desired order.


No, it switches in the order, which was last used!

If you need to switch between two files, you *only* need to select the
second file once and then one Ctrl-TAB will switch between these two files.


Ctrl+Tab ain't it -- that is plain MDI window navigation.

What is needed is a way to switch (open if necessary!) between the .h and
..c/cpp file.

WndTabs (for VS6) provided this feature, and was immensely beneficial. I'm not
aware of a similar capability w/ VS03.
Nov 17 '05 #6
Switch between Header and CPP file (not tested in VC7.x):
http://www.codeproject.com/macro/hcppswitchermacro.asp

Switch between Header and CPP file for VS.NET
http://www.codeproject.com/macro/h_cpp_switcher.asp

Visual Assist has this feature as well.

Nov 17 '05 #7

"Jochen Kalmbach" <no********************@holzma.de> wrote in message
news:Xn*********************************@207.46.24 8.16...
Hi Peter van der Goes,

No, it switches in the order, which was last used!

If you need to switch between two files, you *only* need to select the
second file once and then one Ctrl-TAB will switch between these two files.
--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/


But, not necessarily in the desired order, depending on what you've been
doing.

--
Peter [MVP Visual Developer]
Jack of all trades, master of none.
Nov 17 '05 #8
Julie wrote:

Jochen Kalmbach wrote:

Hi Peter van der Goes,
Thanks, Jochen. You're correct of course, with one caveat.
If I have 6 or 7 source code files open in the editor, ctrl-tab seems
to switch between files in the order they were opened, not necessarily
in the desired order.


No, it switches in the order, which was last used!

If you need to switch between two files, you *only* need to select the
second file once and then one Ctrl-TAB will switch between these two files.


Ctrl+Tab ain't it -- that is plain MDI window navigation.

What is needed is a way to switch (open if necessary!) between the .h and
.c/cpp file.

WndTabs (for VS6) provided this feature, and was immensely beneficial. I'm not
aware of a similar capability w/ VS03.


Here is the macro that I came up with:

Sub OpenAssociatedSourceFile()
If ActiveDocument Is Nothing Then
Microsoft.VisualBasic.Beep()
Return
End If
If ActiveDocument.FullName Is Nothing Then
Microsoft.VisualBasic.Beep()
Return
End If
Dim FileName As String = ActiveDocument.FullName
If FileName.EndsWith(".cpp") Then
FileName = FileName.Substring(0, FileName.LastIndexOf(".")) + ".h"
ElseIf FileName.EndsWith(".h") Then
FileName = FileName.Substring(0, FileName.LastIndexOf(".")) +
".cpp"
Else
FileName = Nothing
End If
If System.IO.File.Exists(FileName) Then
DTE.ItemOperations.OpenFile(FileName)
Else
Microsoft.VisualBasic.Beep()
End If
End Sub
I then assigned it to Ctrl+Shift+H to switch between .cpp/h files.
Nov 17 '05 #9
Julie wrote:
Here is the macro that I came up with:

Sub OpenAssociatedSourceFile()
If ActiveDocument Is Nothing Then
Microsoft.VisualBasic.Beep()
Return
End If
If ActiveDocument.FullName Is Nothing Then
Microsoft.VisualBasic.Beep()
Return
End If
Dim FileName As String = ActiveDocument.FullName
If FileName.EndsWith(".cpp") Then
FileName = FileName.Substring(0,
FileName.LastIndexOf(".")) + ".h" ElseIf
FileName.EndsWith(".h") Then FileName =
FileName.Substring(0, FileName.LastIndexOf(".")) + ".cpp"
Else
FileName = Nothing
End If
If System.IO.File.Exists(FileName) Then
DTE.ItemOperations.OpenFile(FileName)
Else
Microsoft.VisualBasic.Beep()
End If
End Sub
I then assigned it to Ctrl+Shift+H to switch between .cpp/h files.


Thanks for posting this - I'm sure others will find it useful.

Personally, I've never wanted the feature. My C++ coding style rarely
results in matched .cpp/.h pairs, so I don't miss the feature. I do
remember this feature from way back in Turbo C/Borland C++ though.

-cd
Nov 17 '05 #10
Hi Peter van der Goes,
No, it switches in the order, which was last used!


But, not necessarily in the desired order, depending on what you've been
doing.


"It switches in the order, which was last used"

Is this wrong !?

As Juli said: "This is plain MDI window navigation."

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
Nov 17 '05 #11
Carl Daniel [VC++ MVP] <cp*****************************@mvps.org.nospam > wrote:
[...]

Thanks for posting this - I'm sure others will find it useful.
Yes, I would have, if Visual Assist wouldn't
have taken care of it already.
Personally, I've never wanted the feature. My C++ coding style rarely
results in matched .cpp/.h pairs, so I don't miss the feature.
It certainly doesn't match all the time for
me -- but rarely ever? What do you do then?
I do
remember this feature from way back in Turbo C/Borland C++ though.
Oh yeah, in BCB it was CTRL-F6 (as opposed
to CTRL-TAB which was normal MDI behaviour). :)
-cd

Schobi

--
Sp******@gmx.de is never read
I'm Schobi at suespammers dot org

"The presence of those seeking the truth is infinitely
to be prefered to those thinking they've found it."
Terry Pratchett
Nov 17 '05 #12

"Jochen Kalmbach" <no********************@holzma.de> wrote in message
news:Xn*********************************@127.0.0.1 ...
Hi Peter van der Goes,
No, it switches in the order, which was last used!


But, not necessarily in the desired order, depending on what you've been
doing.


"It switches in the order, which was last used"

Is this wrong !?

As Juli said: "This is plain MDI window navigation."

--
Greetings
Jochen

Practicing a little revisionist history?
I'm not arguing that point Jochen. You started this subthread by pointing
out that my comment on using the mouse to select the desired tab is not the
"fastest" way. My point is: given the standard behavior of Ctrl-Tab (I agree
that it is "... plain MDI window navigation."), using the mouse may well be
more efficient for some, depending on circumstances. To each his own, eh?

--
Peter [MVP Visual Developer]
Jack of all trades, master of none.
Nov 17 '05 #13
Hi Peter van der Goes,
I'm not arguing that point Jochen. You started this subthread by
pointing out that my comment on using the mouse to select the desired
tab is not the "fastest" way. My point is: given the standard behavior
of Ctrl-Tab (I agree that it is "... plain MDI window navigation."),
using the mouse may well be more efficient for some, depending on
circumstances. To each his own, eh?


Maybe I misunderstood it... sorry...

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
Nov 17 '05 #14
Hendrik Schober wrote:
Carl Daniel [VC++ MVP]
Personally, I've never wanted the feature. My C++ coding style
rarely results in matched .cpp/.h pairs, so I don't miss the feature.


It certainly doesn't match all the time for
me -- but rarely ever? What do you do then?


value-types tend to be generic, hence entirely in the header with no
corresponding .cpp file.

application types use abstract interfaces, smart pointers and factory
patterns, so the full implementation type is typically declared entirely in
the .cpp file and there is no corresponding .h file.

-cd
Nov 17 '05 #15
Torben Laursen wrote:
Hi

Can anyone tell me what is the short-cut to switch between a .h and .cpp
file, thanks

Torben Laursen

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.786 / Virus Database: 532 - Release Date: 29/10/2004

I have one for Visual Studio .NET 2003 that I wrote (the API's changed
from 2002 so it will take some serious changes to work with the older
version). It needs to be imported into the Macro IDE and bound to a
hotkey or button.

It could probably be optimized to be faster but it does the job (esp if
the files are already open).

Imports EnvDTE
Imports System.Windows.Forms
Imports Microsoft.VisualStudio.VCProjectEngine
'Note: You may have to manually go into the 'References' of this macro project and add Microsoft.VisualStudio.VCProjectEngine to it manually

Public Module gbxUtilityMacros
Private Function SearchProjectForFiles(ByRef proj As VCProject, ByRef file1 As String, ByRef file2 As String, ByRef file3 As String, ByRef file4 As String) As Boolean
Dim fileColl As IVCCollection = proj.Files
Dim filecount As Integer = fileColl.Count
Dim counter As Integer
For counter = 1 To filecount
Dim file As VCFile = fileColl.Item(counter)
Dim origname As String = file.Name
Dim fullname As String = file.FullPath
If (String.Compare(origname, file1, True) = 0) Then
DTE.Documents.Open(fullname)
Return True
ElseIf (String.Compare(origname, file2, True) = 0) Then
DTE.Documents.Open(fullname)
Return True
ElseIf (String.Compare(origname, file3, True) = 0) Then
DTE.Documents.Open(fullname)
Return True
ElseIf (String.Compare(origname, file4, True) = 0) Then
DTE.Documents.Open(fullname)
Return True
End If
Next
Return False
End Function
Sub HeaderSourceSwitch()
On Error Resume Next

Dim sExtOffset As String = InStrRev(ActiveDocument.Name, ".")
Dim sExt As String
If sExtOffset > 0 Then
sExt = Right(ActiveDocument.Name, ActiveDocument.Name.Length - sExtOffset)
End If

sExt = LCase(sExt)
Dim sFileBase As String = Left(ActiveDocument.Name, Len(ActiveDocument.Name) - Len(sExt) - 1)

Dim PossibleMatch1 As String
Dim PossibleMatch2 As String
Dim PossibleMatch3 As String
Dim PossibleMatch4 As String

' valid extension?
If sExt = "h" Or sExt = "hpp" Or sExt = "hxx" Then
PossibleMatch1 = sFileBase & ".cpp"
PossibleMatch2 = sFileBase & ".cxx"
PossibleMatch3 = sFileBase & ".cc"
PossibleMatch4 = sFileBase & ".c"
ElseIf sExt = "c" Or sExt = "cpp" Or sExt = "cxx" Then
PossibleMatch1 = sFileBase & ".hpp"
PossibleMatch2 = sFileBase & ".hxx"
PossibleMatch3 = sFileBase & ".hh"
PossibleMatch4 = sFileBase & ".h"
Else
Exit Sub
End If

' is the needed file already opened?
Dim doc As Document
For Each doc In DTE.Documents
If (String.Compare(doc.Name, PossibleMatch1, True) = 0) Then
If doc.ActiveWindow() Is Nothing Then
DTE.Documents.Open(doc.FullName)
Else
doc.Activate()
End If
Exit Sub
End If
If (String.Compare(doc.Name, PossibleMatch2, True) = 0) Then
If doc.ActiveWindow() Is Nothing Then
DTE.Documents.Open(doc.FullName)
Else
doc.Activate()
End If
Exit Sub
End If
If (String.Compare(doc.Name, PossibleMatch3, True) = 0) Then
If doc.ActiveWindow() Is Nothing Then
DTE.Documents.Open(doc.FullName)
Else
doc.Activate()
End If
Exit Sub
End If
If (String.Compare(doc.Name, PossibleMatch4, True) = 0) Then
If doc.ActiveWindow() Is Nothing Then
DTE.Documents.Open(doc.FullName)
Else
doc.Activate()
End If
Exit Sub
End If
Next

Dim ThisProj As VCProject = DTE.ActiveDocument.ProjectItem.ContainingProject() .Object
If SearchProjectForFiles(ThisProj, PossibleMatch1, PossibleMatch2, PossibleMatch3, PossibleMatch4) Then
Exit Sub
End If

Dim sol As Solution = DTE.Solution
Dim loopproj As Project
For Each loopproj In sol.Projects
Dim Proj As VCProject = loopproj.Object
'Minor optimization: Skip the project we already searched above
If Not Proj Is ThisProj Then
If SearchProjectForFiles(Proj, PossibleMatch1, PossibleMatch2, PossibleMatch3, PossibleMatch4) Then
Exit Sub
End If
End If
Next
End Sub
End Module

Nov 17 '05 #16
Hendrik Schober wrote:

Carl Daniel [VC++ MVP] <cp*****************************@mvps.org.nospam > wrote:
[...]

Thanks for posting this - I'm sure others will find it useful.


Yes, I would have, if Visual Assist wouldn't
have taken care of it already.
Personally, I've never wanted the feature. My C++ coding style rarely
results in matched .cpp/.h pairs, so I don't miss the feature.


It certainly doesn't match all the time for
me -- but rarely ever? What do you do then?
I do
remember this feature from way back in Turbo C/Borland C++ though.


Oh yeah, in BCB it was CTRL-F6 (as opposed
to CTRL-TAB which was normal MDI behaviour). :)


Actually -- Ctrl+F6 came first, and was the standard, and is still supported in
word processors (e.g. Word) where Ctrl+Tab is is used to insert a Tab character
in certain cases.
Nov 17 '05 #17
Carl Daniel [VC++ MVP] <cp*****************************@mvps.org.nospam > wrote:
Hendrik Schober wrote:
Carl Daniel [VC++ MVP]
Personally, I've never wanted the feature. My C++ coding style
rarely results in matched .cpp/.h pairs, so I don't miss the feature.
It certainly doesn't match all the time for
me -- but rarely ever? What do you do then?


value-types tend to be generic, hence entirely in the header with no
corresponding .cpp file.


I see. However, I still try to put as much
code into cpp files as possible, so I have
cpp files for almost all generic types, too.
And we don't have that many of those.
(Although mopst of those we have, are probably
by me. <g> )
application types use abstract interfaces, smart pointers and factory
patterns, so the full implementation type is typically declared entirely in
the .cpp file and there is no corresponding .h file.
Mhmm. Not for us. There a lot of ground
inbetween that most of our code seems to
cover.
-cd

Schobi

--
Sp******@gmx.de is never read
I'm Schobi at suespammers dot org

"The presence of those seeking the truth is infinitely
to be prefered to those thinking they've found it."
Terry Pratchett
Nov 17 '05 #18

"Jochen Kalmbach" <no********************@holzma.de> wrote in message
news:Xn*********************************@127.0.0.1 ...
Hi Peter van der Goes,
I'm not arguing that point Jochen. You started this subthread by
pointing out that my comment on using the mouse to select the desired
tab is not the "fastest" way. My point is: given the standard behavior
of Ctrl-Tab (I agree that it is "... plain MDI window navigation."),
using the mouse may well be more efficient for some, depending on
circumstances. To each his own, eh?


Maybe I misunderstood it... sorry...

--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/


I apologize as well. I should have shut up at least two messages ago.
Seems the macros offered or referenced here are a far better solution than
any of the built in features.

Peter
Nov 17 '05 #19

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by varois83 | last post: by
10 posts views Thread by Niels Dekker (no reply address) | last post: by
99 posts views Thread by Glen Herrmannsfeldt | last post: by
8 posts views Thread by NilsNilsson | last post: by
15 posts views Thread by Steffen Loringer | last post: by
4 posts views Thread by slougheed | last post: by
10 posts views Thread by Jim Langston | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.