zoukankan      html  css  js  c++  java
  • vs2008 同名.cpp和.h文件之间转换的实现(转)

    I’ve been doing a lot of managed C++ programming lately and I had forgotten what a pain it is switching back and forth between the header file and source file.  Back in the days of Visual Studio 6 I had a macro that switched between the CPP and H file, so I went googling, but the macro I found didn’t work very well in VS2008.  Like any good coder, I decided to write it myself instead.

    http://www.alteridem.net/2008/02/26/visual-studio-macro-to-switch-between-cpp-and-h-files/(原文网址)

    If you haven’t written a macro before, here are the steps.

    1. In Visual Studio, go to Tools | Macros | Macros IDE. A new window should open and in the Project Explorer, the MyMacros project should be open.
    2. Right click on the MyMacros project and select Add | Add Module. Name it CppUtilities.  The CppUtilities should open in the editor window.
    3. Add the code from below into the module and save the project.
    1. ‘=====================================================================  
    2. ‘ If the currently open document is a CPP or an H file, attempts to  
    3. ‘ switch between the CPP and the H file.  
    4. ‘=====================================================================  
    5. Public Sub SwitchBetweenSourceAndHeader()  
    6.   Dim currentDocument As String  
    7.   Dim targetDocument As String  
    8.   
    9.   currentDocument = ActiveDocument.FullName  
    10.   
    11.   If currentDocument.EndsWith(“.cpp”, StringComparison.InvariantCultureIgnoreCase) Then  
    12.     targetDocument = Left(currentDocument, Len(currentDocument) - 3) + “h”  
    13.     OpenDocument(targetDocument)  
    14.   ElseIf currentDocument.EndsWith(“.h”, StringComparison.InvariantCultureIgnoreCase) Then  
    15.     targetDocument = Left(currentDocument, Len(currentDocument) - 1) + “cpp”  
    16.     OpenDocument(targetDocument)  
    17.   End If  
    18.   
    19. End Sub  
    20.   
    21. ‘=====================================================================  
    22. ‘ Given a document name, attempts to activate it if it is already open,  
    23. ‘ otherwise attempts to open it.  
    24. ‘=====================================================================  
    25. Private Sub OpenDocument(ByRef documentName As String)  
    26.   Dim document As EnvDTE.Document  
    27.   Dim activatedTarget As Boolean  
    28.   activatedTarget = False  
    29.   
    30.   For Each document In Application.Documents  
    31.     If document.FullName = documentName And document.Windows.Count > 0 Then  
    32.       document.Activate()  
    33.       activatedTarget = True  
    34.       Exit For  
    35.     End If  
    36.   Next  
    37.   If Not activatedTarget Then  
    38.     Application.Documents.Open(documentName, “Text”)  
    39.   End If  
    40. End Sub  

    If you switch back to Visual Studio and open the Macro Explorer, you should see the new module CppUtilities and the new macro SwitchBetweenSourceAndHeader in the tree.  You could run the macro from here, but it is much easier to bind it to a keystroke.

    1. Click on Tools | Options then go to the Environment | Keyboard tab.
    2. In the Show commands containing: box, type CppUtilities. This should filter the list down to one entry,Macros.MyMacros.CppUtilitities.SwitchBetweenSourceAndHeader.
    3. Click on the Press shortcut keys: text box and then press the keystroke you would like to use to run the macro. If the keystroke is already used, it will show you below in the Shortcut currently used by: dropdown.  When you find one that is unused, click the Assign button to use it.  I use Ctrl+Shift+Alt+Bkspce.
    4. Click OK then open a CPP or H file and give it a try.                                                                                                                                                         
  • 相关阅读:
    git 看不到别人创建的远程分支
    win10 系统开始菜单没反应的解决方法
    Fiddler 抓取 https 设置详解(图文)
    MongoDB + Express + art-template 项目实例-博客管理系统
    使用 XAML 格式化工具:XAML Styler
    [WPF] 在单元测试中使用 Prism 的 EventAggregator,订阅到 ThreadOption.UIThread 会报错
    分别使用 Python 和 Math.Net 调用优化算法
    在 Azure 上执行一些简单的 python 工作
    Linux默认路由与直连路由
    网站使用域名访问而禁止ip访问的配置
  • 原文地址:https://www.cnblogs.com/infiniti/p/3135731.html
Copyright © 2011-2022 走看看