VS2008 在h与cpp文件间切换快捷键

本文介绍了一个Visual Studio宏,帮助用户轻松实现CPP和H文件之间的快速切换,提升开发效率。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

文章出处:http://www.alteridem.net/2008/02/26/visual-studio-macro-to-switch-between-cpp-and-h-files/

1.选择VS工具(T)-->宏(M)

2.在新打开窗口右边项目列表,选择MyMacros --> 打开MyModule

3.粘贴下面代码


    ‘===================================================================== 
    ‘ If the currently open document is a CPP or an H file, attempts to 
    ‘ switch between the CPP and the H file. 
    ‘===================================================================== 
    Public Sub SwitchBetweenSourceAndHeader() 
    Dim currentDocument As String
    Dim targetDocument As String
      currentDocument = ActiveDocument.FullName 
    If currentDocument.EndsWith(“.cpp”, StringComparison.InvariantCultureIgnoreCase) Then
        targetDocument = Left(currentDocument, Len(currentDocument) - 3) + “h” 
        OpenDocument(targetDocument) 
    ElseIf currentDocument.EndsWith(“.h”, StringComparison.InvariantCultureIgnoreCase) Then
        targetDocument = Left(currentDocument, Len(currentDocument) - 1) + “cpp” 
        OpenDocument(targetDocument) 
    End If
    End Sub
    ‘===================================================================== 
    ‘ Given a document name, attempts to activate it if it is already open, 
    ‘ otherwise attempts to open it. 
    ‘===================================================================== 
    Private Sub OpenDocument(ByRef documentName As String) 
    Dim document As EnvDTE.Document 
    Dim activatedTarget As Boolean
      activatedTarget = False
    For Each document In Application.Documents 
    If document.FullName = documentName And document.Windows.Count > 0 Then
          document.Activate() 
          activatedTarget = True
    Exit For
    End If
    Next
    If Not activatedTarget Then
        Application.Documents.Open(documentName, “Text”) 
    End If
    End Sub

4.在MyMacros右键重命名(个人喜好,可改可不改)-->CppUtilities

5.在MyMacros右键生成。

6.回到VS2008,选择工具(T)-->选项(O)

7.在"显示命令包含"输入刚才生成的宏的名字"CppUtilities"

8.在"按快捷键(P)"按下快捷键(本人设定的是Alt+Q,看个人喜好)

9.确定。

10.去体验一下吧。

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值