473,386 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 1904

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: varois83 | last post by:
Hi I am fairly new to PHP/mysql and was reading an online tutorial and learned that my short tags weren't enabled. At this time I have no need for them, my setup apache/mysql/php runs on my PC...
10
by: Niels Dekker (no reply address) | last post by:
Is it possible for a standard compliant C++ compiler to have ( sizeof(short) < sizeof(int) ) and ( sizeof(short) == sizeof((short)0 + (short)0) ) ? Regards, Niels Dekker...
99
by: Glen Herrmannsfeldt | last post by:
I was compiling a program written by someone else about six years ago, and widely distributed at the time. It also includes makefiles for many different systems, so I know it has been compiled...
34
by: Andy | last post by:
Hi, Are 1 through 4 defined behaviors in C? unsigned short i; unsigned long li; /* 32-bit wide */ 1. i = 65535 + 3; 2. i = 1 - 3; 3. li = (unsigned long)0xFFFFFFFF + 3; 4. li = 1...
8
by: NilsNilsson | last post by:
I wrote this: short s1 = 0; short s2 = 1; short s3 = s1 + s2; And gor this compile error message: Cannot implicitly convert type 'int' to 'short' What is wrong here?
15
by: Steffen Loringer | last post by:
Hi, I'm using the following function to join 2 char (byte) into one short on a 32 bit X86 platform: unsigned short joinUnsigShort(unsigned char a,unsigned char b) { unsigned short val = 0;...
4
by: slougheed | last post by:
I encountered a problem after we had converted our declarations of 'unsigned short int' to uint16_t. In one instance, whoever did the conversion failed to delete the 'short' keyword so we had a...
10
by: Jim Langston | last post by:
Is the following well defined? size_t IntVal = 65537; unsigned short Length; if ( IntVal static_cast<unsigned short>( -1 ) ) { std::cout << "Value too long to fit in a short" << std::endl;...
10
by: nyhetsgrupper | last post by:
The following code result in the following compilation error: Error 1 Cannot implicitly convert type 'int' to 'short'. An explicit conversion exists (are you missing a cast?) short a = 1; short...
3
by: mathieu | last post by:
Could someone please tell me what is wrong with the following -ugly- piece of c++ code. Why when I explicititely set the template parameter my gcc compiler start getting confused: bla.cxx: In...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.