VS头文件 源文件切换

问题:头文件和源文件之间使用快捷键切换,可以提高工作效率。本例,设置快捷键:Alt+F2
操作步骤如下:
1.打开:工具 —》宏—》宏 IDE,如图1:
VS2008 头文件和源文件切换 - lys_19850716 - 娃哈哈,营养快线,小Q!
图1
2.添加模块,这里模块名称为 CppUtilities, 如图2, 图3:
VS2008 头文件和源文件切换 - lys_19850716 - 娃哈哈,营养快线,小Q!
图2
  VS2008 头文件和源文件切换 - lys_19850716 - 娃哈哈,营养快线,小Q!
图3
 添加模块 CppUtilities,结果为图4:
VS2008 头文件和源文件切换 - lys_19850716 - 娃哈哈,营养快线,小Q!
 
 图4
3.添加模块代码。在 CppUtilities文件中添加如下代码
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports System.Diagnostics

Public Module CppUtilities

    '=====================================================================  
    ' 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
End Module
4.保存。文件 —》保存MyMacros
5.查看保存结果。打开: 工具 —》 宏—》宏资源管理器,如图5:
VS2008 头文件和源文件切换 - lys_19850716 - 娃哈哈,营养快线,小Q!
图5
 打开 宏资源管理器,结果如图6:
VS2008 头文件和源文件切换 - lys_19850716 - 娃哈哈,营养快线,小Q!
图6
 6.开始设置快捷键。
打开:工具 —》 选项—》环境 —》 键盘,在显示命令里包含输入: CppUtilities,列表中 至少 会筛选一项。如图7:
VS2008 头文件和源文件切换 - lys_19850716 - 娃哈哈,营养快线,小Q!
图7
 在按快捷键输入框中,按下:Alt+F2,点击分配,分配结果,如图8:
VS2008 头文件和源文件切换 - lys_19850716 - 娃哈哈,营养快线,小Q!
图8
点击确定,在VS2008中,试试 Alt+F2的效果。
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值