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!