Switching between. h and. cpp files in,

Source: Internet
Author: User

Switching between. h and. cpp files in,

I recently wrote a lot of C ++ programs. switching between header files and source files is really painful. There is a macro in vc6.0 to implement this switch, but I found this macro is not useful in vs2008. Like other excellent programmers, I decided to write a macro to implement this function.

If you have not written this macro before, follow these steps:
1. Select Tools | Macros IDE in vs and open the macro window;
2. Right-click MyMacros in the left directory and choose Add | Add Module to create a file and rename it CppUtilities. The file will be opened in the editor;
3. Add the following code between the public Module CppUtilities and End Module:

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 IfEnd SubPrivate 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 IfEnd Sub

4. ctrl + S save and Click Tools | Options. In the displayed window, select Environment | Keyboard,
Enter CppUtilities in the text box under Show commands ining;
5. Click the text box below Press shortcut keys and Press the shortcut key you want to set (the blogger uses Alt + F8 );
6. Click OK to go back to the project for testing!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.