Click here to Skip to main content
15,890,123 members
Articles / Programming Languages / C++

'Find Function headers' macro for Visual Studio .NET

Rate me:
Please Sign up or sign in to vote.
3.67/5 (3 votes)
28 May 2002CPOL 71.5K   283   11   4
This macro will help you when you want to quickly move between function headers in your code.

Introduction

As you know there isn't a function like WBGoToNext and WBGoToPrevious in Visual Studio .NET.
So this macro will help you when you want to quickly move between function headers in your code.

It is very simple, so there is no need comment!

VB
' FindFunction macro
'
' Writer : [Asia MVP] Smile Seo
' E-mail : seaousak@hotmail.com
'

Imports EnvDTE
Imports System.Diagnostics

Public Module FindFunction
    Sub BeginningOfFunction()
        Dim ts As TextSelection = DTE.ActiveWindow.Selection
        ts.MoveToPoint(ts.ActivePoint.CodeElement(_
               vsCMElement.vsCMElementFunction).GetStartPoint(vsCMPart.vsCMPartHeader))
    End Sub

    Sub EndOfFunction()
        Dim ts As TextSelection = DTE.ActiveWindow.Selection
        ts.MoveToPoint(ts.ActivePoint.CodeElement( _
                 vsCMElement.vsCMElementFunction).GetEndPoint(vsCMPart.vsCMPartHeader))
    End Sub

    Sub GotoFunctionHeaderUp()
        On Error GoTo ErrorHandler

        BeginningOfFunction()

        ActiveDocument().Selection.FindText("}", vsFindOptions.vsFindOptionsBackwards)
        ActiveDocument().Selection.LineUp()
        BeginningOfFunction()

ErrorHandler:
    End Sub

    Sub GotoFunctionHeaderDown()
        On Error GoTo ErrorHandler

        EndOfFunction()

        ActiveDocument().Selection.FindText("{")
        ActiveDocument().Selection.LineDown()

        BeginningOfFunction()

ErrorHandler:
    End Sub


End Module

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
Korea (Republic of) Korea (Republic of)
Woo Seok Seo have been a Microsoft MVP for 7 years and have translated several books into Korean. Author of C# Programming for Beginner (DevPress, 2001), he is interested in Debugging techniques and .NET technology. Get in touch with Woo Seok Seo at wooseok.seo@gmail.com

Comments and Discussions

 
GeneralThis works pretty well... Pin
Thomas Lunsford6-Aug-03 14:06
Thomas Lunsford6-Aug-03 14:06 
Generalfails in a C++ class method Pin
billdarcy10-Jul-03 5:12
billdarcy10-Jul-03 5:12 
QuestionHow to bind Pin
Robin4-Jun-02 7:47
Robin4-Jun-02 7:47 
AnswerRe: How to bind Pin
S Fewings8-Jul-03 5:15
S Fewings8-Jul-03 5:15 
The name of the module in the Visual studio environment must match the name of the module in the macro
To Bind:-
In VS Macro Explorer select the macro you you wish to add this module to
Select "New Module..." from the context menu
Type in FindFunction
Now edit the module and paste the macro functions inside
Public Module FindFunction<br />
<br />
End Module

The functions should then be available in the Customize Keyboard list

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.