Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

"ClassWizard" in VS.NET 2003

0.00/5 (No votes)
29 May 2003 1  
Simulate the Class Wizard in VS.NET 2003

Introduction

Visual Studio .NET 2003 brings a lot of enhancements but I sometimes miss the good ol' VC6 Class Wizard. Especially when I want to override say OnInitDialog in a CDialog derived class I find it painful to switch to the Class View, find my class in the list and finally right-click to get the Properties. So if you are like me this macro is for you!

How it works

You can use the macro from a .h or a .cpp file. If called from a .cpp file then the macro switches to the corresponding .h file. Then it searches for:

class <Whatever> 
{

If you are used to put the curly brace on the same line as your class declaration then you might have to change the DTE.Find.FindWhat line and remove the\n in it (see code below).

It then closes the Find dialog, synchronizes the Class View with your class and displays the Properties window. You can then click on Events/Messages/Overrides and select the function you wish to override.

Of course I mapped this to Ctrl+W!

The Macro

And here is the code!

Sub ClassWizard()

    Dim a, b As String
    a = DTE.ActiveDocument.FullName()
    tmp = InStr(a, ".cpp")
    If tmp Then
        b = Left(a, Len(a) - 3) + "h"
        DTE.Documents.Open(b, "Text")
    End If

    DTE.ActiveDocument.Selection.StartOfDocument()
    DTE.ExecuteCommand("Edit.Find")
    DTE.Find.FindWhat = "class .*\n\{"
    DTE.Find.PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxRegExpr
    DTE.Find.Execute()
    DTE.Windows.Item(Constants.vsWindowKindFindReplace).Close()
    
    DTE.ExecuteCommand("View.SynchronizeClassView")
    DTE.ExecuteCommand("View.PropertiesWindow")

End Sub

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here